微信小程序 定时器
微信小程序开发交流qq群 173683895承接微信小程序开发。扫码加微信。正文:这是一个demo函数,定时器为10分钟count_down:function(e){var that=this;var my_time = new Date().getTime()wx.setStorageSync('my_time', my_time)...
·
微信小程序开发交流qq群 173683895
承接微信小程序开发。扫码加微信。
正文:
这是一个demo函数,定时器为10分钟
count_down:function(e){
var that=this;
var my_time = new Date().getTime()
wx.setStorageSync('my_time', my_time)
if(!wx.getStorageSync('ok_time')){
wx.setStorageSync('ok_time', my_time + 10 * 60 * 1000)
this.show_img()
}else{
if (wx.getStorageSync('my_time') >= wx.getStorageSync('ok_time')){
this.show_img()
wx.removeStorageSync('ok_time')
}
}
setTimeout(function(){
that.count_down()
},1000)
},
实现:
1 获取当前时间戳并保存到缓存,
2 创建一个10分钟后的时间戳缓存
3 如果目前的时间戳缓存大于等于10分钟后的时间戳缓存,就执行定时器成功的函数并且重置定时器。
4 每隔1秒调用自身函数。
更多推荐

所有评论(0)