数组排序

// 排序方法
compare (namse) {
return (obj1, obj2) => {
const val1 = obj1[namse] * 1
const val2 = obj2[namse] * 1
if (val1 < val2) {
return 1
} else if (val1 > val2) {
return -1
} else {
return 0
}
}
// console.log(rr.sort(this.compare('value'))) 调用方式
},

使用方法
this.allData = this.allData.sort(this.compare(排序条件项))
posted @ 2022-07-14 09:21  李笑吅  阅读(21)  评论(0编辑  收藏  举报