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)
相关推荐
ZC跨境爬虫1 分钟前
跟着 MDN 学CSS day_13 :(深入理解CSS中的元素尺寸调整)
前端·javascript·css·ui·html·tensorflow
threelab24 分钟前
Three.js 加载 3D Tiles 瓦片数据 | 三维可视化 / AI 提示词
开发语言·前端·javascript·人工智能·3d·着色器
百度地图开放平台39 分钟前
我用百度地图 Skills 体系重构了物流调度系统,节省了 90% 的人力
前端·github
JavaAgent架构师1 小时前
前端AI工程化(九):AI Agent平台前端架构设计
前端·人工智能
_洋1 小时前
Three.js加载 .obj文件 和 .gltf文件
开发语言·javascript·ecmascript
梦想CAD控件1 小时前
网页端对DWG图纸进行预览与批注(CAD轻量化)
java·前端·javascript
代码煮茶1 小时前
Vue3 埋点实战 | 从 0 搭建前端用户行为埋点系统
vue.js
JustNow_Man2 小时前
【opencode】安装使用daytona沙箱插件
android·java·javascript
不吃土豆的马铃薯2 小时前
Spdlog 进阶:日志基本控制、日志格式控制、异步记录器
linux·服务器·开发语言·前端·c++
wait2 小时前
Vibe Coding 开发技巧
前端·javascript·人工智能