var timer=null;
startBeat(){
if(this.timer){ //定时器处理小技巧,禁止打开多个
return;
}
this.timer=setInterval(()=>{
console.log(“正在心跳”);
},1000);
}
stopBeat(){
clearInterval(this.timer);
this.timer=null; //定时器处理小技巧,清除定时器后要清空
}
定时器处理技巧
最新推荐文章于 2021-12-07 16:53:50 发布