watch监听(普通和深度监听)

普通

data(){
user: "", // 定义要监听的对象
}

watch: {
// 普通监听值有变化就打印 newVal, oldVal新旧值参数
user(newVal, oldVal){
  console.log("user###", this.user);   
}}

深度监听:监听对象里面的数组或者其他(再里面一层的)

    user: {
      handler() {
        // console.log("user###", this.user);
        // 获取选择后勾选的数量
        this.ScanSum = 0;
          for (let i = 0; i < this.user.borrowToolList.length; i++) {
            if (this.user.borrowToolList[i].checkState == true) {
              this.ScanSum += 1;
            }
          }
      },
      immediate: true, 
      deep: true, //开启深度监听
    },

猜你喜欢

转载自blog.csdn.net/m0_61601708/article/details/131280656