使用的vue
- return内的定义三个变量
timeout: true,
count: '',
timer: null,
- methods内的方法
getCode() {
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.timeout = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--;
} else {
this.timeout = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
}
- HTML
<el-button class="send" size="small" type="primary" @click="send(ruleForm.phone,true)" v-show="timeout">发送验证码
</el-button>
<el-button class="send" size="small" type="primary" disabled v-show="!timeout">{{count}}</el-button>
网友评论