elementui一个form-item里面有多个输入框表单验证
如图
这里是动态表单,增加删除,以下是主要代码:
<el-form-item label="排查内容及频率" prop="values">
<div v-for="(item,index) in form.djList" :key="index">
<el-form-item label="" :prop="`djList.${index}.dj`" :rules="rules.dj" class="inline">
<el-select v-model="item.dj" placeholder="排查内容">
<el-option v-for="item in form.pcnrList"
:key="item.key"
:label="item.value"
:value="item.key">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="" :prop="`djList.${index}.gzplm`" :rules="rules.gzplm" class="inline">
<el-select v-model="item.gzplm" placeholder="排查频率">
<el-option v-for="item in form.pcplList"
:key="item.key"
:label="item.value"
:value="item.key">
</el-option>
</el-select>
</el-form-item>
<el-button v-if="index == 0" type="text" icon="el-icon-plus" @click="addRow"></el-button>
<el-button v-if="index > 0" style="color: #f66" type="text" icon="el-icon-minus" @click="deleteRow(index)"></el-button>
</div>
</el-form-item>
下拉框el-select循环的数组 比如我这里的pcnrList要放在form里面.
下面是规则的截图
增删表单
addRow() {
this.form.djList.push({
dj: '',
gzplm: ''
})
},
deleteRow(index) {
this.form.djList.splice(index, 1);
},
css
.inline {
display: inline-block;
}
好了 差不多的照抄就行了