表格中某项上/下移动
<el-table-column label="操作" width="230">
<template slot-scope="scope">
// 这里的v-if判断是表示表格第一行不显示上移,最后一行不显示下移
<el-button type="text" @click="onMovePosition(scope.row,'up')" v-if="pagination.pageSize*(pagination.pageNum-1)+scope.$index>0">上移</el-button>
<el-button type="text" @click="onMovePosition(scope.row,'down')" v-if="pagination.pageSize*(pagination.pageNum-1)+scope.$index<pagination.total-1">下移</el-button>
</template>
</el-table-column>
data(){
return{
pagination: { // 分页
pageSize: 20,
pageNum: 1,
total: 0
}
}
},
methods:{
onMovePosition(row, type) {
const params = {
id: row.id,
direction: type == 'up' ? 1 : 2, // 1上移 2下移
tempType: 3
}
this.$requestInternet.post('/api/xx', params).then(res => {
this.$message.success('移动成功')
})
}
}
网友评论