Open openks opened 6 years ago
element-ui
表格嵌套校验
// 点击加号生成一个name1+name2 name1和name2需校验非空
name1 +
name2
form1: {
form2: [{
name1: '',
name2: '',
}],
},
rules: {
name: [
{ required: true, message: '该项为必填项,请输入内容', trigger: 'blur' },
],
},
<el-form :label-position="labelPosition"
label-width="110px"
:rules="rules"
ref="ruleForm"
:model="form1">
<div v-for="(it,key1) in form1.form2"
:key="key1">
<el-form-item label="名称1"
:rules="rules.name"
:prop="'form2['+key1+'].name1'">
<el-input v-model="it.name1"></el-input>
</el-form-item>
<el-form-item label="名称2"
:rules="rules.name"
:prop="'form2['+key1+'].name2'">
<el-input v-model="it.name2"></el-input>
</el-form-item>
</div>
</el-form>
直接调用表单需要校验的某个prop即可(问了两个同事都不知道有这个方法),官方示例