notes :prop It's not just about rules The validation item in the rule , At the same time, it corresponds to us form-item Under the v-model Value .prop The bound class should be associated with el-form-item Under the v-model The value of corresponds to . Otherwise, even if the check element input character , Also you will be prompted “ Please enter ” And so on , It causes unfriendly calibration problems .
// Clear the form verification prompt
if (this.$refs['XXX']) {
// Delayed execution
this.$nextTick(function () {
this.$refs['XXX'].clearValidate();
})
};
vue User defined form verification , Whether the test is passed or not, we must add callback();
validateDatasourceNm(rule, value, callback) {
let reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/; // Only positive numbers are allowed
if (value === '') {
callback(); // If this sentence does not have There will be unknown problems .
} else {
if (!reg.test(value)) {
callback(new Error(this.ruleNames[rule.fullField]));
}
callback();
}
}
Extended reading :
《 Vue Advanced ( Every single one three ): About vue.js element ui Form validation this.$refs[formName].validate() The problem of 》