element-ui 表单验证,给自定义方法传参数

2020-04-16  本文已影响0人  IamaStupid

别忘了给el-form-item设置prop值

下面代码的required不能加,因为这一项绑定的值不在formData,加了虽然会有红色号,但是验证会遇到麻烦,去除,自定义样式,给item加一个class=“red-star",然后设置label的:before样式

<el-form :inline="true" :model="formData"
             :show-message="false"
             :rules="rules">
      <el-form-item label=" 一级名称" required prop="pl1Name">
        <el-input v-model="treeNodeData.data.label"></el-input>
      </el-form-item>
......

rules: {
        pl1Name: [
          {
            validator: (rule, value, callback) => {
              valid.notNull(rule, value, callback, this.treeNodeData.data.label)
            },
            trigger: 'blur'
          }
        ],
        pl1NameEn: [
          { validator: valid.notNull, trigger: 'blur' }
        ],
        pl1Weight: [
          {
            validator: (rule, value, callback) => {
              valid.notNull(rule, value, callback, this.treeNodeData.data.precent)
            },
            trigger: 'blur'
          }
        ]
      }
    }
上一篇下一篇

猜你喜欢

热点阅读