当前位置: 首页 > news >正文

vue3+elementPlus table里添加输入框并提交校验

<template><div><el-form :model="info" ref="forms"><el-tableref="tableRef":data="info.data"border><el-table-column align="center" property="name" label="*姓名"><template #default="row"><el-form-item :prop="'data.' + row.$index + '.name'" :rules="formRules.name"><el-input placeholder="请输入姓名" v-model="info.data[row.$index].name" /></el-form-item></template></el-table-column><el-table-column align="center" property="role" label="角色"><template #default="row"><el-form-item :prop="'data.' + row.$index + '.role'" :rules="formRules.role"><el-input placeholder="请输入角色" v-model="info.data[row.$index].role" /></el-form-item></template></el-table-column></el-table></el-form><el-button type="primary" @click="submitForm()">Submit</el-button></div>
</template>
<script setup lang="ts">
import {ref, reactive} from 'vue'
import type { FormInstance } from 'element-plus'
let info:any = reactive({data:[{id: 0,name: '',role:''},{id: 1,name: '',role:''}]
})
const formRules = reactive({name: [{ required: true, message: '请输入姓名', trigger: 'change' }],role: [{ required: true, message: '请输入角色', trigger: 'change' }]
})
const forms = ref<FormInstance>()
const submitForm = async () => {if (!forms) returnreturn await forms.value?.validate((valid: any) => {if (valid) {console.log('submit!')} else {console.log('error submit!')return false}})
}
</script>

http://www.lryc.cn/news/128679.html

相关文章:

  • ios swift5 collectionView 瀑布流(两列)
  • 创建一个简单的HTML Viewer应用程序
  • 无公网IP,公网SSH远程访问家中的树莓派教程
  • 「UG/NX」Block UI 超级截面SuperSection
  • 高层建筑全景vr火灾隐患排查模拟培训软件助力群众防范火灾伤害
  • 【WPF】 本地化的最佳做法
  • VS2017编译同事VS2022创建的库,报错无法运行rc.exe
  • Leetcode49. 字母异位词分组
  • 设计模式之工厂方法模式(FactoryMethod)
  • python的进度条tqdm库,显示时进度条不换行设置
  • spark的使用
  • 力扣:66. 加一(Python3)
  • Go的标准库Context理解
  • Nuxt3_1_路由+页面+组件+资源+样式 使用及实例
  • Kafka第三课
  • elasticsearch修改es集群的索引副本数量
  • 【SpringCloud】Ribbon定制化配置
  • Mac terminal 每次打开都要重新配置文件
  • el-button实现按钮,鼠标移入显示,移出隐藏
  • uniapp+uview封装小程序请求
  • idea常见错误大全之:解决全局搜索失效+搜索条件失效(条件为空)+F8失灵
  • 【论文阅读】基于深度学习的时序预测——LTSF-Linear
  • 02.FFMPEG的安装和添加硬件加速自编译
  • elementUI 的上传组件<el-upload>,自定义上传按钮样式
  • 【卷积神经网络】卷积,池化,全连接
  • 【SA8295P 源码分析】76 - Thermal 功耗 之 /dev/thermalmgr 相关调试命令汇总
  • 以太网(一):PoE供电
  • 骨传导耳机游泳能戴吗?骨传导游泳耳机哪个牌子好?
  • 18万字应急管理局智慧矿山煤矿数字化矿山技术解决方案WORD
  • 【mysql】MySQL CUP过高如何排查?