递归倒计时,小程序页面刷新,出现多个倒计时
每刷新一次页面,多一个倒计时
setCountDown: function() {
let time = 1000;
let endTime = this.data.endTime;
let showTime = this.data.showTime;
let showTimeHh = this.data.showTimeHh;
let showTimeMm = this.data.showTimeMm;
let showTimeSs = this.data.showTimeSs;
if (endTime <= 0) {
endTime = 0;
this.setData({
showTime: "订单已结束",
editTrue: false,
isDisabled:false,
titlea:"欢迎下次使用"
});
clearInterval(this.setCountDown);
this.timeover();
return false
}
let formatTime = this.getFormat(endTime);//格式化时间方法
console.log("formatTime",this.getFormat(endTime))
endTime -= time;
showTime = `${formatTime.hh}:${formatTime.mm}:${formatTime.ss}`;
showTimeHh = `${formatTime.hh}`;
showTimeMm = `${formatTime.mm}`;
showTimeSs = `${formatTime.ss}`;
this.setData({
showTime: showTime,
endTime: endTime,
showTimeHh : showTimeHh,
showTimeMm : showTimeMm,
showTimeSs : showTimeSs
});
console.log("时间",this.data.showTime)
setTimeout(this.setCountDown, time);
},
onHide里面每次清除倒计时就行了