vue数组中交换位置,数组重新排序

这个博客展示了如何使用JavaScript操作数组,通过点击上箭头和下箭头来交换表格中行的位置。`top()`函数将当前行与前一行互换,而`bottom()`函数则将当前行与后一行互换,实现元素在数组内的位置调整。
摘要由CSDN通过智能技术生成

在这里插入图片描述
this.tableData 数组
index 点击行的索引

top(index, row) {
         // 点击上箭头,获取当前行下标 
 
         this.tableData.splice(
            index,
            1,
            ...this.tableData.splice(index - 1, 1, this.tableData[index])
         );
         // console.log(this.tableData);
      },
// 点击下箭头,获取当前行下标 
bottom(index, row) {
         // console.log(index, row);
         this.tableData.splice(
            index,
            1,
            ...this.tableData.splice(index + 1, 1, this.tableData[index])
         );
      },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值