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)
相关推荐
爱上妖精的尾巴几秒前
5-41 WPS JS宏 数组迭代基础测试与双数组迭代的使用方法测试
前端·javascript·wps
Tisfy5 分钟前
“豆包聊天搜索” —— 直接在Chrome等浏览器地址栏开启对话
前端·chrome·豆包
Data_agent5 分钟前
京东商品价格历史信息API使用指南
java·大数据·前端·数据库·python
weixin_440730507 分钟前
HTML中的css和js的书写样式
javascript·css·html
大学生资源网16 分钟前
基于Vue的网上购物管理系统的设计与实现(java+vue+源码+文档)
java·前端·vue.js·spring boot·后端·源码
diudiu_3321 分钟前
XSS跨站脚本攻击
前端·xss
终极前端开发协会21 分钟前
【web前端 - 齐枭飞】乾坤【qiankun】应用,主项目与子项目交互详细代码,里面有详细代码,可直接粘贴过去 直接应用 ,
前端·前端框架·交互
闲蛋小超人笑嘻嘻37 分钟前
localStorage用法详解
前端
Swift社区40 分钟前
用 RN 的渲染模型,反推 Vue 列表的正确拆分方式
前端·javascript·vue.js
Mr_chiu40 分钟前
微前端从入门到精通:Vue开发者的大型应用架构演进指南
前端·架构