<el-button plain :disabled="disabled" @click="sendcode" class="btnCode">{{btntxt}}</el-button>
data中定义
btntxt: '获取验证码',
disabled:false,
// 获取验证码
sendcode() {
if(this.ruleForm.tel==''){
alert("请输入手机号码");
return;
}
// 以下是接口,自行更改
sendSms_forAllUser({
phone: this.ruleForm.tel
}).then(res => {
this.$message.success(res.msg);
this.disabled = true;
this.time = 60;
this.timer();
})
},
// 计时
timer() {
if (this.time > 0) {
this.time--;
this.btntxt = this.time + "s,后重新获取验证码";
setTimeout(this.timer, 1000);
} else{
this.time = 0;
this.btntxt = "获取验证码";
this.disabled = false;
}
},