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