前提:列表下钻表单填写或者表单里面含有列表填写
使用el-form 自带的 rules 进行规则设置
1. html
<el-form ref="formInline" :model="formInline" :rules="formInlineRules" size="small" label-width="140px">
<el-form-item label="检查内容:" prop="checkContentJsonArr">
<el-table ref="list" :data="formInline.checkContentJsonArr" border>
<el-table-column align="center" label="一级要素" prop="oneElement" width="130">
<template slot-scope="scope">
<el-form-item class="table-required" :prop="'checkContentJsonArr.' + scope.$index + '.oneElement'" :rules="formInlineRules.oneElement">
<el-input v-model="scope.row.oneElement" type="textarea" placeholder="一级要素" />
</el-form-item>
</template>
</el-table-column>
</el-table>
</el-form-item>
</el-form>
2. 规则
formInlineRules: {
checkContentJsonArr: [{ required: true, message: '请添加检查内容', trigger: 'change' }],
oneElement: [{ required: true, message: '请输入一级要素', trigger: 'blur' }]
},
3. 校验
this.$refs.formInline.validate((valid) => {
if (valid) {
// 校验通过要做的事情
} else {
return false
}
})