码迷,mamicode.com
首页 > 微信 > 详细

微信小程序倒计时60S

时间:2018-07-10 19:13:02      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:int   lse   options   val   UNC   tin   tap   led   this   

<button class="code-b {{disabled?‘code-h‘:‘‘}}" disabled=‘{{disabled}}‘ data-id="2" bindtap="getVerificationCode">{{time}}</button>
var interval = null //倒计时函数
Page({
  data: {
    time: ‘获取验证码‘, //倒计时 
    currentTime: 60
  },
})
getCode: function (options) {
    let that = this;
    let currentTime = that.data.currentTime
    console.log(1)
    interval = setInterval(function () {
      currentTime--;
      that.setData({
        time: `重新获取(${currentTime}s)`
      })
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          time: ‘重新获取‘,
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000)
  },
  getVerificationCode() {
    this.getCode();
    let that = this
    that.setData({
      disabled: true
    })
  },

 

微信小程序倒计时60S

标签:int   lse   options   val   UNC   tin   tap   led   this   

原文地址:https://www.cnblogs.com/baifubin/p/9290862.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!