代码改变世界

settimeout和setinterval的验证码倒计时(包括请求接口不重复)

2021-01-25 17:37  小罗世界  阅读(195)  评论(0)    收藏  举报

请求接口不重复,主要就是两个函数

 countDown () {
      let second = 60
      let timer = null;
      timer = setInterval(() => {
        second--;
        if (second > 0) {
          this.btnDisiable = false
          this.count = second + 's'
        } else {
          clearInterval(timer);
          this.btnDisiable = true
          this.count = "发送验证码"
        }
      }, 1000);
    },
    getEmallCode () {
      getMailCode({ umsEmail: this.emall }) //邮箱验证码接口
      // this.count = 60
      this.countDown()
    },
    // countDown () {
    //   if (this.count > 0) {
    //     this.btnDisiable = false
    //     this.count--
    //   } else {
    //     this.btnDisiable = true
    //   }
    //   setTimeout(() => {
    //     this.countDown()
    //   }, 1000)
    // }