一、排序方法:
sortByQueryParams(property, asc = true) {//默认升序
asc = asc == true ? -1 : 1
return function (value1, value2) {
let a = value1[property]
let b = value2[property]
return a < b ? asc : a > b ? asc * -1 : 0
}
},
二、使用:
#升序
this.dataList = this.dataList.sort(this.sortByQueryParams('sort'))
#或者
this.dataList = this.dataList.sort(this.sortByQueryParams('sort',true))
#降序
this.dataList = this.dataList.sort(this.sortByQueryParams('sort',false))