<el-table-column
align="center"
label="排序">
<template slot-scope="scope">
<el-button
size="mini"
icon="el-icon-bottom"
:disabled="scope.$index === tableData.length - 1"
@click="moveDown(scope.$index, scope.row)"
>
</el-button>
<el-button
size="mini"
icon="el-icon-top"
:disabled="scope.$index === 0"
@click="moveUp(scope.$index, scope.row)"
>
</el-button>
</template>
</el-table-column>
js
// 上移
moveUp(index, row) {
if (index > 0) {
const upDate = this.tableData[index - 1];
this.tableData.splice(index - 1, 1);
this.tableData.splice(index, 0, upDate);
} else {
alert("已经是第一条,不可上移");
}
},
// 下移
moveDown(index, row) {
if (index + 1 === this.tableData.length) {
alert("已经是最后一条,不可下移");
} else {
const downDate = this.tableData[index + 1];
this.tableData.splice(index + 1, 1);
this.tableData.splice(index, 0, downDate);
}
},
el-table 排序
猜你喜欢
转载自blog.csdn.net/qq_44716001/article/details/131983409
今日推荐
周排行