小程序验证码倒计时

var countdown = 60;
var settime = function (that) {
  if (countdown == 0) {
    that.setData({
      is_show: true
    })
    countdown = 60;
    return;
  } else {
    that.setData({
      is_show: false,
      last_time: countdown
    })
    countdown--;
  }
  setTimeout(function () {
    settime(that)
  }, 1000)
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    last_time: '',
    is_show: true
  },
  clickVerify: function () {
    var that = this;
    // 将获取验证码按钮隐藏60s,60s后再次显示
    that.setData({
      is_show: (!that.data.is_show) //false
    })
    settime(that);
  }
})
posted @ 2022-11-08 09:25  SultanST  阅读(12)  评论(0编辑  收藏  举报