不使用cleartimeout有什么风险嘛,我是用这种方法停止的,取消定时器我一直取消不了?
发布于 6 年前 作者 yma 10988 次浏览 来自 官方Issues

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哪用的不对

1 回复

var t = settimeout(function(),t); cleartimeout(t)

回到顶部