setInterval
data: {
setInter: '',
},
//简单计时器
startSetInter: function () {
var that = this;
that.data.setInter = setInterval(
function () {
//函数
}, 1000);
},
//清除计时器 即清除setInter
endSetInter: function () {
var that = this;
clearInterval(that.data.setInter)
},
[https://baike.baidu.com/item/setInterval](https://baike.baidu.com/item/setInterval)
不闪烁,倒计时,后台持续执行,提示框
/**
* 页面的初始数据
*/
data: {
openTime: 20.0,
setInter: '',
}
//开始开锁计时器
startSetInter: function () {
var that = this;
//----
//---
that.data.setInter = setInterval(function () {
var numVal = that.data.openTime - 1;
that.setData({ openTime: numVal });
wx.showToast({
title: '执行中'+that.data.openTime.toString()+'秒',
icon: 'none'
})
if (that.data.openTime ==0){
that.endSetInter();
wx.showToast({
title: '倒计时结束!',
icon: 'none'
})
}
}, 1000);
},
//清除计时器 即清除setInter
endSetInter: function () {
var that = this;
wx.hideLoading()
clearInterval(that.data.setInter)
},
setTimeout
https://www.jianshu.com/p/fc9a08ca2c92
网友评论