正常情况下input框为空是可以callback,但是点击获取验证码的时候如果input为空没有callback,但是输入错误格式的内容就有callback,
求大神帮忙看看,帮忙解决一下,贴下代码
`
export default {
data(){
var emailAdd = (rule, value, callback) => {
if(value === ''){
callback(new Error('请输入邮箱地址'));
}else if(value !==''){
if(!this.checkEmail(value)){
callback(new Error('请输入正确的邮箱地址'))
}else{
// 调用后台接口判断邮箱是否已经使用
callback();
}
}else{
callback();
}
}
return{
emailRule:{
emailAddress:[
{ required: true, validator: emailAdd, trigger: 'blur' }
],
}
}
},
methods:{
//点击获取验证码
verifyEmail(){
let email = this.emailForm.emailAddress
if(this.checkEmail(email)){
console.log(email)
const TIME_COUNT = 60;
if (!this.timer) {
this.count = TIME_COUNT;
this.emailShow = false;
this.timer = setInterval(() => {
if (this.count > 0 && this.count <= TIME_COUNT) {
this.count--;
} else {
this.emailShow = true;
clearInterval(this.timer);
this.timer = null;
}
}, 1000)
}
}
},
checkEmail(str) {
let emailReg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
if (emailReg.test(str)) {
return true;
} else {
return false;
}
},
}
}
`