Home > Web Front-end > JS Tutorial > 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

小云云
Release: 2018-05-15 15:39:07
Original
2811 people have browsed it

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>
Copy after login

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)
       }
    }  
  }
Copy after login

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!

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