vue手机号验证码倒计时
data(){
return{
show1: true,
count1:""
}
}
const TIME_COUNT1 = 60;
if (!this.timer1) {
this.count1 = TIME_COUNT1;
this.show1 = false;
this.timer1 = setInterval(() => {
if (this.count1 > 0 && this.count1 <= TIME_COUNT1) {
this.count1--;
} else {
this.show1 = true;
clearInterval(this.timer1);
this.timer1 = null;
}
}, 1000);
}
<span style="margin-left: 20px;font-size: 18px;border: 1px solid #ea7313;padding: 5px 15px;border-radius: 5px;" v-show="show1" @click="getCodes">获取验证码</span>
<span style="margin-left: 20px;font-size: 18px;border: 1px solid #ea7313;padding: 5px 15px;border-radius: 5px;" v-show="!show1" class="count">{{ count1 }} 秒</span>