原生微信小程序,手机号获取验证码倒计时

  data: {
    count: 60,
    mobile: '',
    code: '获取验证码',
  },
  //验证码
  textCode: function () {
    let that = this
    // 手机号码格式验证
    if (!(/^1[3456789]\d{9}$/.test(this.data.mobile))) {
      wx.showToast({
        title: '输入手机号有误',
        icon: 'none',
        duration: 2000
      })
      return;
    }
    if (that.data.code !== '获取验证码') {
      return
    }
    const countDown = setInterval(() => {
      if (that.data.count <= 0) {
        that.setData({
          count: 60,
          code: '获取验证码'
        })
        clearInterval(countDown)
        return
      }
      that.data.count--
      that.setData({
        count: that.data.count,
        code: that.data.count < 10 ? `请等待0${that.data.count}s` : `请等待${that.data.count}s`
      })
    }, 1000);
    // 调用验证码接口
    that.textCode_http()
  },
posted @   喜欢Tb  阅读(6)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示