直接上代码。
<el-table :data='tableData' >
...
...
<el-table-column label="操作" align="center" width="140" >
<template slot-scope="scope">
<el-button type="text" @click="upMove(scope.$index,scope.row)">上移</el-button>
<el-button type="text" @click="upDown(scope.$index,scope.row)">下移</el-button>
</template>
</el-table-column>
</el-table>
export default{
methods:{
upMove(index, row) {
if (index <= 0) {
this.$message.error('不能继续向上移动')
} else {
const upData = this.tableData[index - 1]
this.tableData.splice(index - 1, 1)
this.tableData.splice(index, 0, upData)
}
},
upDown(index, scope) {
if (index === (this.tableData.length - 1)) {
this.$message.error('不能继续向下移动')
} else {
const downData = this.tableData[index + 1]
this.tableData.splice(index + 1, 1)
this.tableData.splice(index, 0, downData)
}
}
}
}