vue中:
<div class="getCode">
<van-button
slot="button"
:class="[!disabled ? 'signature-code-button' : '']"
:disabled="disabled"
@click="getCode"
>{{ disabled ? `重新发送 ${resendTime}` : "获取验证码" }}</van-button>
</div>
methods:中点击事件
// 点击获取验证码
getCode() {
this.verificationValue = "";
let params = {
orderId: this.verificationId
};
getVerifyCode(params).then(res => {
if (res.code == "1") {
Toast(res.data.errorMessage);
this.disabled = true;
this.resendTime = 59;
this.interval = setInterval(() => {
if (this.resendTime > 0) {
this.resendTime -= 1;
} else {
this.resendTime = 60;
clearInterval(this.interval);
this.disabled = false;
}
}, 1000);
} else {
Toast(res.msg);
}
});
},
上图