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

vue2+element-ui新增编辑表格+删除行

实现效果:

 

代码实现 :

          <el-table :data="dataForm.updateData"border:header-cell-style="{'text-align':'center'}":cell-style="{'text-align':'center'}"><el-table-column label="选项字段"align="center"prop="name"><template slot-scope="scope"><el-form-item :prop="'updateData.' + scope.$index + '.formName'":rules="[{ required: true, message: '请输入', trigger: 'blur' },{ min: 1, max: 20, message: '长度在1到 20个字符', trigger: 'blur' }]"><el-input v-model="scope.row.formName"clearable></el-input></el-form-item></template></el-table-column><el-table-column fixed="right"label="操作"><template slot-scope="scope"><el-button @click.native.prevent="addRow(scope.$index,scope.row,dataForm.updateData)"type="text"size="small">新增</el-button><el-button @click.native.prevent="deleteRow(scope.$index,scope.row,dataForm.updateData)"type="text"size="small"v-if="dataForm.updateData.length!=1">移除</el-button></template></el-table-column></el-table><script>
export default {data () {return {dataForm: {// 自定义字段updateData: [{// id: '',formName: ''}]// 其他...    }}},methods: {// addRow 新增 自定义字段表格行addRow (index, rows, item) {// console.log(index, rows, item)// this.dataForm.updateData.push({//   // sort: this.dataForm.updateData && this.dataForm.updateData.length > 0 ? this.dataForm.updateData.length + 1 : 1,//   id: null,//   formName: ''// })// 数组中添加新元素item.splice(index + 1, 0, { formName: '' })},// deleteRow 删除 自定义字段表格行deleteRow (index, rows, item) {// console.log(index, '当前行索引', rows, '删除的目标行')// 从index这个位置开始删除数组后的1个元素item.splice(index, 1)// this.$confirm('删除当前行, 是否继续?', '提示', {//   confirmButtonText: '确定',//   cancelButtonText: '取消',//   type: 'warning'// }).then(() => {//   item.splice(index, 1)//   // this.delArrId.push(rows.id) // 被删除的id数组集合//   // rows.isDelete = 1// }).catch(() => {//   this.$message({//     type: 'info',//     message: '已取消删除'//   })// })},}
}
</script>

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

相关文章:

  • Day05-组织架构-角色管理
  • 【LLM】二、python调用本地的ollama部署的大模型
  • 20240708 每日AI必读资讯
  • 为什么KV Cache只需缓存K矩阵和V矩阵,无需缓存Q矩阵?
  • VS code修改底部的行号的状态栏颜色
  • 【鸿蒙学习笔记】MVVM模式
  • 端、边、云三级算力网络
  • java —— JSP 技术
  • 【Python学习笔记】菜鸟教程Scrapy案例 + B站amazon案例视频
  • Pycharm的终端(Terminal)中切换到当前项目所在的虚拟环境
  • Nginx 高效加速策略:动静分离与缓存详解
  • Unity3D 游戏摇杆的制作与实现详解
  • 从nginx返回404来看http1.0和http1.1的区别
  • MySQL 代理层:ProxySQL
  • 异步主从复制
  • 论文解析——Full Stack Optimization of Transformer Inference: a Survey
  • selenium处理cookie问题实战
  • (十五)GLM库对矩阵操作
  • android中activity与fragment之间的各种跳转
  • 动态规划算法-以中学排课管理系统为例
  • 本安防爆手机:危险环境下的安全通信解决方案
  • 算法学习笔记(8)-动态规划基础篇
  • 数据库常见问题(持续更新)
  • 定个小目标之刷LeetCode热题(40)
  • Linux--线程(概念篇)
  • Mojo: 轻量级Perl框架的魔力
  • Python 游戏服务器架构优化
  • 13 学习总结:指针 · 其一
  • golang 项目打包部署环境变量设置
  • 【Linux进程】进程优先级 Linux 2.6内核进程的调度