vue深度监听对象

深度监听对象

  data() {
    return {
      obj:{
        age:18
      }
    }
  },
  watch:{
    obj:{
      handler(newVal, oldVal){
      },
      deep:true, // 深度监听
      immediate:true, // 初始化监听
    }
  }

深度监听对象中的值(借用computed)

  data() {
    return {
      obj:{
        age:18
      }
    }
  },
  computed:{
    newAge:function(){
      return this.obj.age;
    }
  },
  watch:{
    newAge(newVal, oldVal){
      console.log(11111, newVal);
    }
  }
posted @ 2022-04-24 11:32  不叫一日闲过  阅读(386)  评论(0编辑  收藏  举报