vue.$watch

about watch

第一种

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export default {
name: 'vessel',
data () {
return {
msg: '容器',
vesselArr:this.$store.state.vesselArr
}
},
created (){
this.$watch('vesselArr',function(p){
$(ifmbody).find('.addText').each(function(i){
$(this).html(p[i].inner)
})
},{deep:true})
}
}
</script>

第二种

1
2
3
4
5
6
7
var app =new Vue({
data:{
msg:'hello world!'
}
})
app.$watch('msg',function(newMsg,oldMsg){},{deep:true})

deep:true 是深度监测 如果加上这个 下边所有的变化都会给反应,如果不写就只能监测到第一层