提供两个样例,主要注意<el-form-item>
中的prop
样例一
language-html1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| <template> <el-form ref="dynamicValidateForm" :model="dynamicValidateForm" label-width="120px" class="demo-dynamic" > //重点关注el-form-item标签中的prop内容 <el-form-item v-for="(domain, index) in dynamicValidateForm.domains" :key="domain.key" :label="'Domain' + index" :prop="'domains.' + index + '.value'" :rules="{ required: true, message: 'domain can not be null', trigger: 'blur', }" > <el-input v-model="domain.value"></el-input> </el-form-item> </el-form> </template>
<script lang="ts"> export default { data() { return { dynamicValidateForm: { domains: [ { key: 1, value: '', }, ], email: '', }, } }, } </script>
|
样例二
language-html1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <template> <el-form :model="queryParams" style="width: 100%"> <el-table :data="queryParams.items"> <el-table-column label="移动数量" width="100"> <template #default="scope"> <div style="display: flex; align-items: center"> <el-form-item style="width: 100px;padding: 0px;margin: 0px" :prop="'items.'+scope.$index+'.moveAmount'" :rules="{ required: true, message: '不能为空', trigger: 'blur',}"> <el-input-number class="number" :controls="false" v-model="scope.row.moveAmount"></el-input-number> </el-form-item> </div> </template> </el-table-column> </el-table> </el-form> </template>
<script setup> const queryParams = reactive({ factory1: undefined, factory2: undefined, commentText: undefined, items:[] }) </script>
|