<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
相关推荐
大怪v6 小时前
【搞发🌸活】不信书上那套理论!亲测Javascript能卡浏览器Reader一辈子~西陵6 小时前
Nx带来极致的前端开发体验——任务缓存Panda__Panda6 小时前
docker项目打包演示项目(数字排序服务)10年前端老司机7 小时前
Promise 常见面试题(持续更新中)nueroamazing8 小时前
PPT-EA:PPT自动生成器WebDesign_Mu10 小时前
为了庆祝2025英雄联盟全球总决赛开启,我用HTML+CSS+JS制作了LOL官方网站噢,我明白了10 小时前
前端js 常见算法面试题目详解学编程的小虎10 小时前
用 Python + Vue3 打造超炫酷音乐播放器:网易云歌单爬取 + Three.js 波形可视化做好一个小前端10 小时前
后端接口获取到csv格式内容并导出,拒绝乱码LuckySusu11 小时前
【vue篇】Vue 项目中的静态资源管理:assets vs static 终极指南