美文网首页微信小程序
微信小程序时间,计时器setInterval,setTimeou

微信小程序时间,计时器setInterval,setTimeou

作者: 若风_412d | 来源:发表于2019-08-29 10:19 被阅读0次

    setInterval

    data: {
        setInter: '',
    },
    
    //简单计时器
    startSetInter: function () {
       var that = this;
       that.data.setInter = setInterval(
       function () {
           //函数
       }, 1000);
    },
    
    //清除计时器 即清除setInter
    endSetInter: function () {
       var that = this;
       clearInterval(that.data.setInter)
    },
    
    [https://baike.baidu.com/item/setInterval](https://baike.baidu.com/item/setInterval)
    
    

    不闪烁,倒计时,后台持续执行,提示框

      /**
       * 页面的初始数据
       */
      data: {
        openTime: 20.0,
        setInter: '',
    }
    
    //开始开锁计时器
      startSetInter: function () {
    
        var that = this;
    
    
    
        //----
      
        //---
       that.data.setInter = setInterval(function () {
      
    
         var numVal = that.data.openTime - 1;
    
         that.setData({ openTime: numVal });
         wx.showToast({
           title: '执行中'+that.data.openTime.toString()+'秒',
           icon: 'none'
         })
         if (that.data.openTime ==0){
    that.endSetInter();
           wx.showToast({
             title: '倒计时结束!',
             icon: 'none'
           })
    }
    
        }, 1000);
    
      },
    
      //清除计时器 即清除setInter
      endSetInter: function () {
        var that = this;
           wx.hideLoading()
        clearInterval(that.data.setInter)
      },
    
    

    setTimeout

    https://www.jianshu.com/p/fc9a08ca2c92

    相关文章

      网友评论

        本文标题:微信小程序时间,计时器setInterval,setTimeou

        本文链接:https://www.haomeiwen.com/subject/yqibectx.html