美文网首页
js验证码倒计时

js验证码倒计时

作者: 大号火龙果 | 来源:发表于2020-02-04 16:02 被阅读0次
  getAuthCodeFu() {
//判断是否可以点击
      if (this.authCodeAble == false) return false;
      if (this.phone == "") {
        this.$toast("请输入手机号码");
        return false;
      }
      var phone = this.phone;
      if (!/^1[0-9]{10}$/.test(phone)) {
        this.$toast({
          message: "手机号格式有误"
        });
        return false;
      }
      let wait = 60;
      let _this = this;
//obj是要替换的标签内容
      function cuntDown(obj) {
        if (wait == 0) {
          _this.authCodeAble = true;
          obj.innerHTML = "获取验证码";
        } else {
          _this.authCodeAble = false;
          obj.innerHTML = "重新发送(" + wait + "s)";
          wait--;
          setTimeout(function() {
            cuntDown(obj);
          }, 1000);
        }
      }
      // 倒计时
      cuntDown(this.$refs.authCode);
      this.$api.own.getAuthCode(this.phone).then(res => {
        console.log(res);
        if (res.data.code == 1) {
          console.log(res.data.data.code);
          this.getAuthCode = res.data.data.code;
        } else {
          this.$toast(res.data.msg);
        }
      });
    }

相关文章

网友评论

      本文标题:js验证码倒计时

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