微信小程序定时器setTimeout 和跳转页面定时器销毁clearInterval
页面初始数据
Page({ data: { timer : '',定时器循环方法
/* * 定时器循环方法 */ ==forChat()== { var timerTem = setTimeout(function () { console.log("!@#$%^&*(&^%$#@#$%^&"); that.forChat() }, 3000) var that = this // 保存定时器name that.setData({ timer: timerTem }) },调用定时器循环
/** * 生命周期函数--监听页面加载 */ onLoad: function(options) { var that = this //调用定时器循环 ==that.forChat();== wx.request({ .........以下代码无关省略定时器销毁 : 看了一些文章 在页面跳转的时候销毁定时器是在wx.redirectTo({方法里 或者是onHide里, 后来测试发现并不是这样实现的, 销毁的方法用clearInterval()方法 在onUnload 里,功能是监听页面卸载
/** * 生命周期函数--监听页面卸载 */ onUnload: function() { //销毁定时器 console.log("+++++++++onUnload++++++++++") clearInterval(this.data.timer); },以上测试可用~













