欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Vue实现table上下移动排序

程序员文章站 2022-07-14 16:45:58
...

基于element-ui框架:

================ data ===================
HotTableList:[]

================ html ===================
<template v-slot="scope">
    <el-button  @click="upindex(scope.$index,scope.row)">上移</el-button>
    <el-button  @click="downindex(scope.$index,scope.row)">下移</el-button>
</template>

================ 上移 ===================
upindex(index, row) {
if (index > 0) {
let upDate = this.HotTableList[index - 1];
this.HotTableList.splice(index - 1, 1);
this.HotTableList.splice(index, 0, upDate);
} else {
this.$message.warning(“已经是第一条了!”);
return false;
}
},

================ 下移 ===================
downindex(index, row) {
if (index + 1 === this.HotTableList.length) {
this.$message.warning(“已经是最后一条了!”);
return false;
} else {
let downDate = this.HotTableList[index + 1];
this.HotTableList.splice(index + 1, 1);
this.HotTableList.splice(index, 0, downDate);
}
},

相关标签: vue