效果示例
代码实现
<el-button
size="small"
type="danger"
icon="el-icon-delete"
circle
@click="handleDelete(scope.row)"
/>
<el-button
v-if="scope.$index !== 0"
size="small"
icon="el-icon-top"
circle
@click="handleUp(scope.$index)"
/>
<el-button
v-if="scope.$index !== dataList.length-1"
size="small"
icon="el-icon-bottom"
circle
@click="handleDown(scope.$index)"
/>
js代码
// 数组项 互换位置
swapArray(arr, index1, index2) {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
return arr;
},
// 上移
handleUp(i) {
this.swapArray(this.dataList, i, i - 1);
},
// 下移
handleDown(i) {
this.swapArray(this.dataList, i, i + 1);
},
// 删除
handleDelete(data) { // 删除按钮 点击函数
this.dataList.splice(this.dataList.indexOf(data), 1);
},