Home  >  Article  >  Web Front-end  >  Vue implements SMS verification code countdown

Vue implements SMS verification code countdown

php中世界最好的语言
php中世界最好的语言Original
2018-04-17 10:35:323051browse

This time I will bring you vue to implement SMS Verification codeCountdown, vue to implement SMS verification code countdownWhat are the precautions, the following is a practical case, let's take a look.

There are two span tags wrapped in the button. Different spans are displayed according to the click status . The key code is the countdown:

 <p id="example">
  <button @click="send">
   <span v-if="sendMsgDisabled">{{time+'秒后获取'}}</span>
   <span v-if="!sendMsgDisabled">send</span>
  </button>
 </p>
 button {
  width: 100px;
  height: 50px background: pink;
 }
var vm = new Vue({
  el: '#example',
  data() {
   return {
    time: 60, // 发送验证码倒计时
    sendMsgDisabled: false
   }
  },
  methods: {
   send() {
    let me = this;
    me.sendMsgDisabled = true;
    let interval = window.setInterval(function() {
     if ((me.time--) <= 0) {
      me.time = 60;
      me.sendMsgDisabled = false;
      window.clearInterval(interval);
     }
    }, 1000);
   }
  }
 })
I believe you have mastered the method after reading the case in this article. Please come for more exciting information. Pay attention to other related articles on php Chinese website!

Recommended reading:



The above is the detailed content of Vue implements SMS verification code countdown. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn