watch监听数据变化
<button @click="num = true">watch</button>
<button @click="num = false">停止</button>
data () {
return {
num: false,
count:0
}
}
watch: {
num(cur, old) {
console.log(cur, old);
this.timer = setInterval(() => {
if (this.num == cur) {
console.log("走起");
this.count++;
} else {
clearInterval(this.timer);
}
}, 3000);
}
}