微信小程序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)
  },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM