<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-button size="mini" :disabled="scope.$index === 0" @click="moveRow(scope.$index, 'up')" >上移</el-button> <el-button size="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>
el-table的行向上移动向下移动,删除选定行
大霞上仙2025-03-22 15:54
相关推荐
闭着眼睛学算法15 分钟前
【双机位A卷】华为OD笔试之【排序】双机位A-银行插队【Py/Java/C++/C/JS/Go六种语言】【欧弟算法】全网注释最详细分类最全的华子OD真题题解可别39019 分钟前
使用Worker打包报错Drift_Dream20 分钟前
深入浅出 requestAnimationFrame:让动画更流畅的利器GIS瞧葩菜24 分钟前
【无标题】彭于晏爱编程32 分钟前
关于表单,别做工具库舔狗风中凌乱的L34 分钟前
vue canvas标注拉不动的猪35 分钟前
什么是二义性,实际项目中又有哪些应用烟袅42 分钟前
LeetCode 142:环形链表 II —— 快慢指针定位环的起点(JavaScript)Ryan今天学习了吗1 小时前
💥不说废话,带你上手使用 qiankun 微前端并深入理解原理!Predestination王瀞潞1 小时前
Java EE开发技术(第六章:EL表达式)