Home > Web Front-end > JS Tutorial > body text

Vue implements SMS verification code countdown

php中世界最好的语言
Release: 2018-04-17 10:35:32
Original
3078 people have browsed it

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>
Copy after login
 button {
  width: 100px;
  height: 50px background: pink;
 }
Copy after login
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);
   }
  }
 })
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template