1、在data中定义定时器
export default{ data(){ timer:null }
2、在methods中使用定时器
this.timer = setInterval(()=>{ //需要做的事情 },1000);
3、在你不用的时候清除定时器
clear(){ clearInterval(this.timer); this.timer = null; }
vue2中如何使用定时器
于 2022-07-08 11:12:44 首次发布
1、在data中定义定时器
export default{ data(){ timer:null }
2、在methods中使用定时器
this.timer = setInterval(()=>{ //需要做的事情 },1000);
3、在你不用的时候清除定时器
clear(){ clearInterval(this.timer); this.timer = null; }