1. el-table属性设置
:data="dataTableTotal.slice((currentPage - 1) * pageSize,currentPage * pageSize) "
// 分页
@sort-change="sortChange"
// 自定义排序方法sortChange
2. el-table-column的sortable属性设置设置为custom才能使用自定义排序
sortable="custom" // 设置为custom才能使用自定义排序方法
3. methods:{}里面定义排序方法
sortChange({ prop, order }) {
this.dataTableTotal.sort(this.compare(prop, order));
},
compare(propertyName, sort) {
return function (obj1, obj2) {
var value1 = obj1[propertyName];
var value2 = obj2[propertyName];
if (typeof value1 === "string" && typeof value2 === "string") {
const res = value1.localeCompare(value2, "zh");
return sort === "ascending" ? res : -res;
} else {
if (value1 <= value2) {
return sort === "ascending" ? -1 : 1;
} else if (value1 > value2) {
return sort === "ascending" ? 1 : -1;
}
}
};
},