for example, the first parameter rule, passed in checkage does not seem to be used in the body of this function, so ask for advice.
<el-form-item label="" prop="age">
<el-input v-model.number="ruleForm2.age"></el-input>
</el-form-item>
export default {
data() {
var checkAge = (rule, value, callback) => {
if (!value) {
return callback(new Error(""));
}
setTimeout(() => {
if (!Number.isInteger(value)) {
callback(new Error(""));
} else {
if (value < 18) {
callback(new Error("18"));
} else {
callback();
}
}
}, 1000);
};
return {
ruleForm2: {
age: ""
},
rules2: {
age: [
{ validator: checkAge, trigger: "blur" }
]
}
};
},
methods: {
submitForm(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
alert("submit!");
} else {
console.log("error submit!!");
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
}
}
}