el-table 使用el-form 表单验证

  1. form定义时,需要定义tableData
javascript 复制代码
const supplyForm = ref({ tableData: [] })

const supplyFormRules = reactive({
	bomNumber: [{ required: true, message: '请填写物料编号', trigger: 'blur' }],
	bomName: [{ required: true, message: '请填写名称', trigger: 'blur' }]
})
  1. 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>
  1. tableData赋值
javascript 复制代码
supplyForm.value.tableData.push(bomItem)
相关推荐
二哈喇子!7 小时前
BOM模型
开发语言·前端·javascript·bom
二哈喇子!7 小时前
Vue2 监听器 watcher
前端·javascript·vue.js
yanyu-yaya8 小时前
前端面试题
前端·面试·前端框架
二哈喇子!8 小时前
使用NVM下载Node.js管理多版本
前端·npm·node.js
GGGG寄了8 小时前
HTML——文本标签
开发语言·前端·html
摘星编程9 小时前
在OpenHarmony上用React Native:ActionSheet确认删除
javascript·react native·react.js
2501_944521599 小时前
Flutter for OpenHarmony 微动漫App实战:推荐动漫实现
android·开发语言·前端·javascript·flutter·ecmascript
Amumu1213810 小时前
Vue核心(三)
前端·javascript·vue.js
CoCo的编程之路10 小时前
2026 前端效能革命:如何利用智能助手实现“光速”页面构建?深度横评
前端·人工智能·ai编程·comate·智能编程助手·文心快码baiducomate
RFCEO10 小时前
HTML编程 课程五、:HTML5 新增语义化标签
前端·html·html5·跨平台·语义化标签·可生成安卓/ios·html最新版本