1、如果需要后端排序,需將sortable設(shè)置為custom蚤假,同時在 Table 上監(jiān)聽sort-change事件,在事件回調(diào)中可以獲取當前排序的字段名和排序順序吧兔,從而向接口請求排序后的表格數(shù)據(jù)磷仰。
<el-table @sort-change='tableSortChange'>
<el-table-column sortable='custom' prop="createTime" label="創(chuàng)建時間">
</el-table-column>
</el-table>
2、定義methods監(jiān)聽sort-change事件
tableSortChange(column) {
this.listQuery.pageNo = 1
if (column.order === 'descending') {
this.listQuery.sortby = column.prop
this.listQuery.order = 'desc'
} else {
this.listQuery.sortby = column.prop
this.listQuery.order = 'asc'
}
this.getList()
}
3境蔼、通過axios提交請求數(shù)據(jù)到后端
getList() {
this.listLoading = true
fetchList(this.listQuery).then(response => {
this.list = response.data.items
this.total = response.data.total
this.listLoading = false
})
}