60秒倒计时

{
      var re = /^(0|86|17951)?(13[0-9]|15[0123456789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
      if (re.test(this.ruleForm.phone)) {
        // 填写正确后,开始发送信息,倒计时
        const TIME_COUNT = 60;
        // 判断时间计时是否存在,不存在则赋值60,不显示发送验证码按钮,计时器启动循环
        if (!this.timer) {
          this.count = TIME_COUNT;
          this.show = false;
          this.Tim = setTimeout(() => {
            this.show = true;
          }, 60000);
          this.timer = setInterval(() => {
            if (this.count > 0 && this.count <= TIME_COUNT) {
              if (this.count == 60) {
                // 点击发送验证码(自己的函数)
                this.cms_fs();
              }
              this.count--;
            } else {
              // 计时器为0的时候显示发送验证码按钮,清空计时器
              this.show = true;
              clearInterval(this.timer);
              this.timer = null;
              return false;
            }
          }, 1000);
        }
      } else {
        // 手机存在,或者手机没有正确填写
        this.show = true;
        this.$message.error("请填写正确手机号!");
      }
    }
原文地址:https://www.cnblogs.com/wulicute-TS/p/12911013.html