微信小程序setInterval的使用和setTimeout的使用

setInterval的使用

//微信小程序设置一个定时器
startSetInter: function(){
     var that = this;
     //将计时器赋值给setInter
     that.data.setInter = setInterval(
         function () {
             console.log('setInterval==' ,等待2s后再执行);
         }
   , 2000)
 },

//微信小程序在页面卸载的时候删除定时器
endSetInter: function(){
     var that = this;
     //清除计时器  即清除setInter
     clearInterval(that.data.setInter)
 },

setTimeout的使用

//延迟0.5s后开始执行
var that = this
wx.showNavigationBarLoading() //在标题栏中显示加载
setTimeout(function() {
  wx.hideNavigationBarLoading() //完成停止加载
  wx.stopPullDownRefresh() //停止下拉刷新
}, 500);

 onUnload: function () {
  var that =this;
  //清除计时器 即清除setInter
  clearInterval(that.data.setInter)
  },

猜你喜欢

转载自www.cnblogs.com/xiaotiancai/p/12550251.html
今日推荐