Page({
data: {
style_img: '',
second: '0' + 0,
countdown: '00:00',
count: 0,
leftTime: 0
},
countTime() {
var that = this;
let count = that.data.count
let leftTime = that.data.leftTime
console.log(count)
if (count == 0) {
count = count + 1
that.setData({
count: count
})
} else {
console.log(leftTime)
leftTime = leftTime + 100
that.setData({
leftTime: leftTime
})
}
var s, ms;
if (leftTime >= 0 && leftTime<105000) {
s = Math.floor(leftTime / 1000 % 60);
ms = Math.floor(leftTime % 1000);
ms = ms < 100 ? "0" + ms : ms
s = s < 10 ? "0" + s : s
that.setData({
countdown: s + ":" + ms,
})
//递归每秒调用countTime方法,显示动态时间效果
setTimeout(that.countTime, 100);
} else {
let countdown = this.data.countdown
console.log('已截止')
that.setData({
countdown: countdown
})
}
},
drawEndBtn: function(){
var that = this
var leftTime = that.data.leftTime
leftTime = 105000
this.setData({
leftTime:leftTime
})
that.countTime()
//clearTimeout(leftTime)
},
// onUnload: function () {
// var that =this;
// clearTimeout(that.data.leftTime)
// },
感谢大家解答 看看cleartimeout哪用的不对