data(){
return{
timer: null,
}
},
mothed{
//在需要时, 调用开始定时器
startTimer() {
this.timer = window.setInterval(() => {
setTimeout(
this.searchData(), 0
);
}, 3000 * 5); // 5秒
},
//在不需要时, 清除定时器
clearTimer() {
clearInterval(this.timer);
this.timer = null;
},
}
vue 创建,清除定时器 ; 轮询方法
最新推荐文章于 2024-06-14 10:40:58 发布