其他分享
首页 > 其他分享> > vue 60s倒计时按钮

vue 60s倒计时按钮

作者:互联网

vue 60s倒计时按钮

  <!-- 手机号 -->
    <InputGroup type="number" 
    v-model="phone" 
    placeholder="手机号"
    :btnTitle="btnTitle" 
    :disabled="disabled" 
    :error="errors.phone"
    @btnClick="getVerifyCode"/>


export default {
  name: 'Login',
  data() {
    return {
        phone:"",
        verifyCode:"",
        errors:{},
        btnTitle:"获取验证码",
        disabled:false

    }
  },
  methods: {
      getVerifyCode() {
          if(this.validatePhone()){
              // 发送网络请求
            this.validateBtn();
          }
      },

      validateBtn() {
       let time = 60;
       let timer = setInterval(() => {
           if(time == 0) {
               clearInterval(timer);
               this.btnTitle = "获取验证码";
               this.disabled = false;
           }else{
               //倒计时
               this.btnTitle = time + "s";
               this.disabled = true;
               time--;
           }
       },1000)
      },

 

标签:disabled,btnTitle,vue,false,60s,timer,倒计时,time
来源: https://blog.csdn.net/lxn111111/article/details/117170263