監視監視 (通常監視と詳細監視)

普通

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

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

深い監視: 配列またはその他のオブジェクトを監視します (内部の 1 つの層)

    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