数据
data: function(){
return {
a: true,
b: {
c:1,
b:2
}
}
}
监测数据 a 的变化
watch: {
a:function(newValue, oldValue) {
console.log(newValue)
}
},
监测数据 b.c 的变化 ,可以通过 computed 做中间层来指定对象属性
computed: {
bc() {
return this.b.c;
}
},
watch: {
bc(newValue, oldValue) {
console.log(newValue)
}
},
其它方法,这是 vuejs api 中介绍的方法
// 键路径
vm.$watch('a.b.c', function (newVal, oldVal) {
// 做点什么
})