- form定义时,需要定义tableData
javascript
const supplyForm = ref({ tableData: [] })
const supplyFormRules = reactive({
bomNumber: [{ required: true, message: '请填写物料编号', trigger: 'blur' }],
bomName: [{ required: true, message: '请填写名称', trigger: 'blur' }]
})
- html绑定
html
<el-form :model="supplyForm" ref="supplyFormRef" inline-message class="supply-form-table">
<el-table
:data="supplyForm.tableData"
border
style="width: 100%"
@cell-click="handleCellEnter"
scrollbar-always-on
highlight-current-row
empty-text="暂无数据"
max-height="420"
stripe
:header-cell-style="{ background: '#f5f7fa' }"
:row-style="{ 'background-color': '#fdf6ec' }"
>
<el-table-column label="序号" prop="bomNo" width="80">
<template v-slot="scope"> {{ scope.$index + 1 }}</template>
</el-table-column>
<el-table-column prop="bomNumber" label="物料编号">
<template #default="scope">
<el-form-item :prop="`tableData.[${scope.$index}].bomNumber`" :rules="supplyFormRules.bomNumber">
<el-input class="cell-input" v-model="scope.row.bomNumber" size="small"
/></el-form-item>
</template>
</el-table-column>
<el-table-column prop="bomName" label="名称">
<template #default="scope">
<el-form-item :prop="`tableData.[${scope.$index}].bomName`" :rules="supplyFormRules.bomName">
<el-input class="cell-input" v-model="scope.row.bomName" size="small"
/></el-form-item>
</template>
</el-table-column>
<el-table-column label="操作">
<template #default="scope">
<el-button link @click="() => deleteSupplyRow(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-form>
- tableData赋值
javascript
supplyForm.value.tableData.push(bomItem)