美文网首页
Vue之watch同时监听多个属性的简略写法

Vue之watch同时监听多个属性的简略写法

作者: 好奇的猫猫猫 | 来源:发表于2022-01-12 16:08 被阅读0次

1.先在computed里

computed:{
dataChange(){
      const {method,methodData,gzjsTable2} = this; //需要监听的属性值
      return{
        method,methodData,gzjsTable2
      }
    }

}

2.在watch里监听

watch:{
dataChange:{
      handler(val) {
          console.log(val);
          this.flagchange++   //排除第一次进页面时会出发watch的情况
          // 默认值有变更的话
          if (this.flagchange > 2) { // 说明监听值有变化
            // 业务代码
          }else{
          // 业务代码
          }
      },
      deep:true
      
    },
}

相关文章

网友评论

      本文标题:Vue之watch同时监听多个属性的简略写法

      本文链接:https://www.haomeiwen.com/subject/tjvwcrtx.html