VUE中
data() {
return {
timer: null, /*定時(shí)器*/
}
}
在方法中或鉤子函數(shù)中使用
// 定時(shí)刷新
if(this.timer === null) {
this.timer = setInterval(() => {
this.drawLine(this.dateValue); // 刷新時(shí)獲取數(shù)據(jù)
}, 600000);
}
清除定時(shí)器
beforeDestroy() {
clearInterval(this.timer);
this.timer = null;
},