getCaptchaCode() {
// console.log('获取验证码');
let _this = this;
const pattern = /^1[3456789]\d{9}$/;
if (!pattern.test(this.SMSForm.phone)) {
_this.$message.error('请输入正确的手机号!');
return;
}
let TIME_COUNT = 60;
if (!_this.timer2) {
_this.countdown = TIME_COUNT;
_this.showCountdown = false;
_this.timer2 = setInterval(() => {
if (_this.countdown > 0 && _this.countdown <= TIME_COUNT) {
_this.countdown--;
} else {
_this.showCountdown = true;
clearInterval(_this.timer2);
_this.timer2 = null;
}
}, 1000);
// console.log('获取验证码');
_this.getCode();
} else {
clearInterval(_this.timer2);
}
},
getCode() {
let phoneObj = {
phone: this.SMSForm.phone,
};
sendCode(phoneObj)
.then((res) => {
console.log(res);
this.$message.success('验证码已发送!');
})
.catch(() => {
this.showCountdown = true;
clearInterval(this.timer2);
this.timer2 = null;
});
},
验证码定时器倒计时
最新推荐文章于 2024-09-06 22:20:29 发布