data:{
minutes:'02',//倒计时 分
seconds:'00',//倒计时 秒
},
onLoad:function(){
this.countdown()
}
countdown(){
var minute = this.data.minutes;
var second = this.data.seconds;
if(second === '00'){ //如果秒降到00,则分减一,秒调整为59
second = 59;
minute = Number(minute) - 1;
minute = minute <= 9 ? '0' + minute : minute;//为了构造两位数显示
}else {
second = Number(second) - 1;
second = second <= 9 ? '0'+ second : second;//为了构造两位数显示
}
const self = this;
setTimeout(function(){
self.setData({
minutes:minute,
seconds:second
})
if(second === '00' && minute === '00'){ //倒计时结束
console.log('aaaa')
}else{
self.countdown();//继续调用自己
}
},100)
}
效果展示