html:
<button type="default" class="button" :disabled="disCaptCha" @click="onCaptcha">{{captchaText}}</button>
model:
captchaText: "获取验证码",
disCaptCha: false,
js:
//获取验证码
onCaptcha() {
const that = this
let phone = that.loginForm.phone;
if (phone == "" || phone == null) {
that.$msg("请输入正确的手机号")
} else {
if (!(/^1[3456789]\d{9}$/.test(phone))) {
that.$msg("请输入正确的手机号")
} else {
let url = "xxxxxxxxx"
that.$post(url, {
phone: phone
}).then(res => {
let countDown = 60;
var newCode = setInterval(function() {
that.disCaptCha = true
that.captchaText = "重新发送(" + countDown + ")"
countDown--;
if (countDown == 0) {
clearInterval(newCode);
that.disCaptCha = false
that.captchaText = "获取验证码"
countDown = 60;
}
}, 1000);
}).catch(error=>{
clearInterval(newCode);
that.disCaptCha = false
that.captchaText = "获取验证码"
countDown = 60;
})
}
}
},