<!-- 获取验证码倒计时60s -->
<div class="input-div">
<button @click="getCode(formData)" class="code-btn" :disabled="!show">
<span v-show="show">获取验证码</span>
<span v-show="!show" class="count">重新发送({{count}})</span>
</button>
</div>
<!-- 获取验证码倒计时60s -->
data里:
TIME_COUNT1:60,//验证码倒计时60s
formData1: {
phone1:'',
code1:'',
},
count1:'',
show1:true,
methods里:
// 验证码倒计时60s
getCode(formData){
if (!this.timer) {
this.count = this.TIME_COUNT;
this.show = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= this.TIME_COUNT) {
this.count--;
} else {
this.show = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
},
来源:CSDN
作者:M_SSY
链接:https://blog.csdn.net/M_SSY/article/details/89356819