首页 > 微信 > 详细

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

时间:2020-03-23 10:30:20      阅读:306      评论:0      收藏:0      [点我收藏+]

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)
  },

 

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

原文:https://www.cnblogs.com/xiaotiancai/p/12550251.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!