1. 程式人生 > >登入註冊中的驗證碼倒計時

登入註冊中的驗證碼倒計時

<span v-if="sendDisabled">{{time+'秒後獲取'}}</span>

<span v-if="!sendDisabled" @click="sends">獲取驗證碼</span>
data{

 return {

      time: 60, // 傳送驗證碼倒計時

      sendMsgDisabled: false,

     }

}
methods: {

    sends() {
        let _this = this;
        _this.sendMsgDisabled = true;
        let interval = setInterval(function() {
         if (_this.time-- <= 0) {
          _this.time = 60;
          _this.sendMsgDisabled = false;
          clearInterval(interval);
         }
       }, 1000);
    }

}