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: '', 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!