一,对整个对象监视
watch:{
obj:{
handler(newV,oldV){
console.log('obj changed')
},
deep: true,//深度遍历
immediate: true//默认false,设置为true会立即执行
}
}
二,对指定key进行监视
watch: {
"dataobj.name": {
handler(newV, oldV) {
console.log("obj changed");
}
}
}
三,结合computed
computed(){
ar(){
return this.obj.name
}
},
watch:{
ar(newV,oldV){
console.log('changed')
}
}