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)
相关推荐
输出输入1 小时前
前端核心技术
开发语言·前端
Mintopia1 小时前
Web 安全与反编译源码下的权限设计:构建前后端一体的信任防线
前端·安全·编译原理
林深现海1 小时前
Jetson Orin nano/nx刷机后无法打开chrome/firefox浏览器
前端·chrome·firefox
EchoEcho1 小时前
深入理解 Vue.js 渲染机制:从声明式到虚拟 DOM 的完整实现
vue.js
黄诂多1 小时前
APP原生与H5互调Bridge技术原理及基础使用
前端
前端市界1 小时前
用 React 手搓一个 3D 翻页书籍组件,呼吸海浪式翻页,交互体验带感!
前端·架构·github
文艺理科生1 小时前
Nginx 路径映射深度解析:从本地开发到生产交付的底层哲学
前端·后端·架构
千寻girling2 小时前
主管:”人家 Node 框架都用 Nest.js 了 , 你怎么还在用 Express ?“
前端·后端·面试
C澒2 小时前
Vue 项目渐进式迁移 React:组件库接入与跨框架协同技术方案
前端·vue.js·react.js·架构·系统架构
xiaoxue..2 小时前
合并两个升序链表 与 合并k个升序链表
java·javascript·数据结构·链表·面试