//正确写法
getPhoneCode() {
let This = this;
let data = {
username: This.registerForm.username,
captcha: This.registerForm.captcha
};
if (data.username == '' || data.captcha == '') {
this.$refs['registerForm'].validateField('username');
this.$refs['registerForm'].validateField('captcha');
} else {
axios.post(regcode, data).then((res) => {
}
})
//以下是错误写法,这样会发送两次请求
This.$refs.registerForm.validateField(['username', 'captcha'], (error) => {
if (!error) {
axios.post(regcode, data).then((res) => {
})
} else {
console.log('error submit!!');
return false;
}
})