el-form form validation in element-ui, verification is only performed when the submit button is clicked

Adding a   :validate-event="false" attribute to the el-input tag will eliminate the need to verify the legality of the value during the input process. It will only be verified when the submit button is clicked:

// ......

<el-form :inline="true" :model="formData" ref="formDataRef" :rules="formRules">
  <el-form-item v-else label="IP地址:" prop="ip">
      <el-input
      class="ip-ipt"
      ref="ipInput0"
      :validate-event="false"
      v-model="ipArr[0]"
      maxlength="3"
      @input="nextFocus(0)" />
  </el-form-item>
</form>


// ......


let formRules = ref({
  ip: { required: true, trigger: ['blur', 'change'], message: '请输入正确的IP地址' }
});
const formDataRef= ref();



// ......



// 提交事件
const onSubmit = () => {
  ipInput.value.validate((valid: boolean) => {
    if (valid) {}
  })
}

Guess you like

Origin blog.csdn.net/qq_21473443/article/details/129954004