微信小程序获取验证码倒计时

时间:2018-08-31 21:22:29   收藏:0   阅读:262
  getVerificationCode: function() {
    var that = this;
    var currentTime = that.data.currentTime;
    that.setData({
      codename: currentTime + ‘秒‘,
      disabled:true
    })
    var interval = setInterval(function() {
      that.setData({
        codename: (currentTime - 1) + ‘秒‘
      })
      currentTime--;
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          codename: ‘重新获取‘,
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000)
  },

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!