如果你需要监听 props 值的变化,可以使用一个计算属性来实现。计算属性会自动监听 props 对象的变化,并在依赖的 props 发生变化时触发相应逻辑。
props: {
count: {
type: Number,
default: 0
}
},
computed: {
countWatcher: function() {
// 在计算属性中可以监听到 props.count 的变化
return this.count;
}
},
watch: {
countWatcher: function(newValue, oldValue) {
// 监听 countWatcher 的变化
console.log("props.count 的值已变为:" + newValue);
}
}
如果监听的数据是对象:
computed:{
currentTaskMsgWatcher : function(){
console.log(this.currentTaskMsgJobId,'this.currentTaskMsgJobId1111199999');
return this.currentTaskMsg;
}
},
watch:{
currentTaskMsgWatcher :