// An highlighted blockconst app = getApp();Page({data: {timer:'', //定时器任务},onShow:funciton(){let e = this;//执行定时器任务this.setData({timer:setInterval(function () {      e.init();    }, 1000)})},/**** 请求的方法*/init:function(){var sendData = {};wx.request({      url: url + '/wechat/loginXXX',      data: sendData,      method: 'post',      success: function (res) {      }})},/**** onHide()在小程序生命周期中具有监听小程序隐藏的功能,当切换页面和切换底部菜单栏时将会关闭定时器。*/onHide:function(){ let e = this;clearInterval(e.data.timer);},/**** 生命周期函数--监听页面卸载,当切换页面和切换底部菜单栏时也会关闭定时器。*/onUnload:function(){ let e = this;clearInterval(e.data.timer);},})// onHide()和onUnload()方法都可以实现,使用时二选一即可。

TAG标签: 微信小程序clearinterval

http://www.xiaochengxub.com/read-104140.html