watch: {
checkIndex(newData, oldData) {
this.switchOrNot = true;
console.log("切换了");
console.log(this.switchOrNot);
}
},
methods: {
deleteButton(index) {
this.checkIndex = index;
if (this.oldFlag == index) {
this.switchOrNot = false;
} else {
this.switchOrNot = true;
}
this.singleChoice = this.switchOrNot
? true
: (this.singleChoice = !this.singleChoice);
this.oldFlag = index;
console.log('haha');
}
},
在deleteButton方法中想用watch中switchOrNot变化的值,但是实际上是不行的。
是在函数执行最后再执行watch中的代码的。