<el-form :model="numberValidateForm" ref="numberValidateForm" :rules="rules" label-width="100px" class="demo-ruleForm">
<el-form-item
label="年龄"
prop="age">
<el-input type="number" v-model="numberValidateForm.age"></el-input>
</el-form-item>
根据接口异常提示。用过 validateField
data() {
var ageValidate = (rule, value, callback) => {
if (this.smsMsg) {
callback(new Error(this.smsMsg));
}else{
callback();
}
};
....
rules:{
age:[
{required: true, message: "年龄不能为空", trigger: 'blur'},
{validator: ageValidate}
]
}
提交请求信息,返回错误
submitForm(formName) {
var _this = this;
_this.$refs[formName].validate((valid) => {
if (valid) {
setTimeout(function(){ // 模拟请求
_this.smsMsg = '年龄有误';
if(_this.smsMsg){ // 服务有返回错误
_this.$refs[formName].validateField("age");
_this.smsMsg = '';
}else{ alert("submit") } },1000); } else { console.log('error submit!!'); return false; } }); },