vue 获取短信验证码

♀尐吖头ヾ 提交于 2019-12-02 11:56:16
            <!-- 获取验证码倒计时60s -->
            <div class="input-div">
                <button @click="getCode(formData)" class="code-btn" :disabled="!show">
                    <span v-show="show">获取验证码</span>
                    <span v-show="!show" class="count">重新发送({{count}})</span>
                </button>
            </div>
            <!-- 获取验证码倒计时60s -->

data里:

TIME_COUNT1:60,//验证码倒计时60s
formData1: {
    phone1:'',
    code1:'',
  },
count1:'',
show1:true,

methods里:

    // 验证码倒计时60s
    getCode(formData){
      if (!this.timer) {
        this.count = this.TIME_COUNT;
        this.show = false;
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= this.TIME_COUNT) {
            this.count--;
          } else {
            this.show = true;
            clearInterval(this.timer);
            this.timer = null;
          }
        }, 1000)
      }
    },

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!