标签:this col 目录 中介 两种 使用 end html 对象
在写项目的时候遇到了一个问题,就是需要动态监听data中一个对象的属性的变化。遇到了许多坑,在此过程中也发现了两种解决方案。
  data() {
    return {
      parent:{
        child:1
      }
    };
  },
  watch:{
    ‘parent.child‘:{
      deep:true,
      handler: function(newV, oldV) {
        console.log(newV);
      }
    }
  }
二、通过computed做中介
  computed:{
    newChild(){
      return this.parent.child;
    }
  }
  watch:{
    newChild(newV,oldV){
      alert(newV)
    }
  },
标签:this col 目录 中介 两种 使用 end html 对象
原文地址:https://www.cnblogs.com/gitByLegend/p/11125723.html