1.给定时器起名字
data() {
return {
timer: ""
}
},
2.在created中使用
this.timer = setInterval(() => {
this.settime() //这里是要做到事情
}, 3000);
3.清除定时器,离开页面销毁定时器
beforeDestroy() {
if(this.timer) {
clearInterval(this.timer); //关闭
}
},
1.给定时器起名字
data() {
return {
timer: ""
}
},
2.在created中使用
this.timer = setInterval(() => {
this.settime() //这里是要做到事情
}, 3000);
3.清除定时器,离开页面销毁定时器
beforeDestroy() {
if(this.timer) {
clearInterval(this.timer); //关闭
}
},