Big shots in the element-UI framework custom verification function passed the first rule parameter exactly what to do, and how to solve, and how to use, thank you.

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();
      }
    }
  }
Mar.01,2021

this is the complete form. Rules, will print it out and have a look at it.

Menu