data(){
return {timerFun:function(){},}
}
created(){
this.getData();// 上来先请求一次
this.timer();// 再去执行定时任务
},
methods: {
getData() {... },
timer() {
this.timerFun = setInterval(() => {
this.getData();
},3000)
}
}
}
beforeDestroy() {
clearInterval(this.timerFun);
},
vue实现一个定时器刷新任务
于 2022-05-27 07:20:06 首次发布