一,對整個對象監視
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')
}
}