//倒计时方法
countdown(){
if(this.maxTime>0){//最大时间大于0
this.maxTime--
this.minutes=Math.floor(this.maxTime / 60).toString().padStart(2,'0')
this.seconds=Math.floor(this.maxTime % 60).toString().padStart(2,'0')
}else{
clearInterval(this.timers);
}
},
//开始倒计时
startCountdown(){
this.maxTime=this.timeValue*60;//最大时间赋值
this.timers=setInterval(()=>{
this.countdown()
},1000)
},
//终止倒计时
closeTime(){
this.timeValue=0
this.minutes="00";
this.seconds="00";
this.maxTime=''
clearInterval(this.timers);
},
//暂停开始
stopTime(){
if(this.stopText==="暂停"){
clearInterval(this.timers);
}else if(this.stopText==="开始"){
this.timers=setInterval(()=>{
this.countdown()
},1000)
}
this.stopText=this.stopText==="开始"?"暂停":"开始"
},
vue使用setInterval完成倒计时,带暂停开始
最新推荐文章于 2024-05-27 22:58:54 发布