Home  >  Article  >  Web Front-end  >  A simple example of implementing the 60-second countdown function of verification code in vue

A simple example of implementing the 60-second countdown function of verification code in vue

小云云
小云云Original
2018-05-15 15:39:072763browse

This article mainly introduces how to simply implement the 60-second countdown function of vue verification code. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

html

<span v-show="show" @click="getCode">获取验证码</span>
<span v-show="!show" class="count">{{count}} s</span>

js

 data(){
   return {
    show: true,
    count: &#39;&#39;,
    timer: null,
   }
  },
  methods:{
    getCode(){
      const TIME_COUNT = 60;
      if (!this.timer) {
        this.count = TIME_COUNT;
        this.show = false;
        this.timer = setInterval(() => {
        if (this.count > 0 && this.count <= TIME_COUNT) {
          this.count--;
         } else {
          this.show = true;
          clearInterval(this.timer);
          this.timer = null;
         }
        }, 1000)
       }
    }  
  }

Related recommendations:

Javascript 60-second countdown to get verification code

Implementing the 60-second countdown after sending the SMS verification code

js code to implement the 60-second countdown when clicking the button_javascript skills

The above is the detailed content of A simple example of implementing the 60-second countdown function of verification code in vue. 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