如果对您有帮助,请关注我,加入微信小程序开发交流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秒调用自身函数。