<!-- 获取验证码倒计时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_COUNT:60,//验证码倒计时60s
formData: {
phone:'',
code:'',
},
count:'',
show: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)
}
},