<div style="margin-top: 15px;">
<el-input placeholder="请输入验证码" v-model="code">
<template slot="append">
<el-button
class="code-btn"
:disabled="isDisbaled"
@click="sendCode"
>
{{ codeBtnContent }}
</el-button>
</template>
</el-input>
</div>
countdown: 60,
codeBtnContent: "发送验证码",
isDisbaled: false,
sendCode() {
// 调研延迟读秒函数
this.setTime();
},
// 延时器倒计时
setTime() {
if (this.countdown == 0) {
this.isDisbaled = false;
this.codeBtnContent = "发送验证码";
this.countdown = 60; //60秒过后button上的文字初始化,计时器初始化;
return;
} else {
this.isDisbaled = true;
this.codeBtnContent = this.countdown + "s";
this.countdown--;
}
setTimeout(() => {
this.setTime();
}, 1000); //每1000毫秒执行一次
},