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

el-table的行向上移动向下移动,删除选定行

<template><el-table :data="tableData" border style="width: 100%"><!-- 其他列 --><el-table-column label="ID"><template slot-scope="scope">{{ scope.$index }}</template></el-table-column><el-table-column label="名称" prop="name"></el-table-column><!-- 操作列:上下移动 --><el-table-column label="操作" width="120"><template slot-scope="scope"><el-buttonsize="mini":disabled="scope.$index === 0"@click="moveRow(scope.$index, 'up')">上移</el-button><el-buttonsize="mini":disabled="scope.$index === tableData.length - 1"@click="moveRow(scope.$index, 'down')">下移</el-button><el-button @click="delRow(scope.$index)">删除一行</el-button></template></el-table-column></el-table>
</template><script>
export default {data() {return {tableData: [{ name: "第 1 行",ID:"" },{ name: "第 2 行",ID:"" },{ name: "第 3 行",ID:""},{ name: "第 4 行",ID:""}]};},methods: {// 行移动逻辑moveRow(index, direction) {const newIndex = direction === 'up' ? index - 1 : index + 1;// 边界检查if (newIndex < 0 || newIndex >= this.tableData.length) return;// 交换数组元素const temp = this.tableData[index];this.$set(this.tableData, index, this.tableData[newIndex]);this.$set(this.tableData, newIndex, temp);console.log(this.tableData)},   
  delRow(index){if (this.tableData.length > 0) {//this.tableData.pop(); // 删除数组最后一个元素this.tableData.splice(index,1)}
},
  }
};
</script>

http://www.mrgr.cn/news/94992.html

相关文章:

  • Diffie-Hellman 加密协议介绍 (DH,DHE,ECDHE)
  • docker(1) -- centos镜像
  • CAN及CANFD协议
  • 使用 Promise 和 .then() 解决同异步问题
  • Optiplex 3060 MT 电脑型号与尺寸
  • Qwen2.5-VL 开源视觉大模型,模型体验、下载、推理、微调、部署实战
  • C++基础: Rule of five/zero/three
  • 【数据结构】顺序表(附源码)
  • 《大语言模型》学习笔记(三)
  • 生成PDF文件:从html2canvas和jsPdf渲染到Puppeteer矢量图
  • SSL/TLS 和 SSH 区别
  • 2025最新!人工智能领域大模型学习路径、大模型使用、AI工作流学习路径
  • SpringCloud 学习笔记3(OpenFeign)
  • 【Netty】消息分发处理方式
  • 【数据库】掌握MySQL事务与锁机制-数据一致性的关键
  • MySQL :参数修改
  • 鸿蒙NEXT开发问题大全(不断更新中.....)
  • C++继承 ---- 继承是面向对象三大特性之一【好处:可以减少重复的代码】
  • Python教学:lambda表达式的应用-由DeepSeek产生
  • Direct2D 极速教程(3) —— 画动态淳平