就是在vue项目中,我想做一个监听一个数据,如果这个数据变化了,我的其他功能就变化,如果这个数据没变,那么功能就不变,但是我现在遇到一个问题就是我如果选择了一个数据(该数据是用el-select选择出来的),就是我选择一个数据他就绑定他的table数据,不更改这个数据就不清除绑定他的table,如果更换数据,就清空前面的数据,但是现在问题是,如果我两次都选同一个数据,他也会把table给清除,请问是怎么回事呢,是逻辑错误了是不是,万分感谢
watch: {
'form.id'(newValue,oldValue){
if (this.$refs.tableFile != undefined){
this.$refs.tableFile.clearSelection();
}
}
}
可以试试这样写:
watch: {
'form.id': function(newValue, oldValue) {
// 当 form.id 发生变化时,执行相应的操作
if (newValue !== oldValue && this.$refs.tableFile != undefined) {
this.$refs.tableFile.clearSelection();
}
}
}