vue中监视对象内部变化的三种方法

一,对整个对象监视

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')
 }
}
原文地址:https://www.cnblogs.com/samsara-yx/p/12454054.html