Vue中监听某个对象的属性

  • 为了避免监听整个对象导致效率问题,可以监听某个对象的特定属性
     watch: {
    'deptModel.depts': {
      handler(newVal, oldVal) {
        if (oldVal.length == 4 && newVal.length == 5) {
          this.deptModel.depts = oldVal
          this.$message.warning('最多选择4个科室')
        }
      }
    }
  }

Vue中普通监听的2种定义

// ----- 1
watch: {
    totalMony: function (newVal, oldValue) {
      // your logic
    }
  }
// ----- 2
watch: {
    totalMony(newVal,oldValue) {
      // your logic
    }
  }

相关文章:

  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-01-28
  • 2021-12-29
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案