Vue watch 深层监听
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
}
}
Keep learning