JavaScript按照对象的某个属性进行排序
参考:https://blog.csdn.net/giser_whu/article/details/51485635
CompanyIndex({ _with: 'location' }) .then((res) => { if (res.data && res.success) { // this.companyList = res.data const companyList1 = res.data function sortBy(obj1, obj2) { const val1 = obj1.offline_reader_count const val2 = obj2.offline_reader_count if (val1 < val2) { return 1 } else if (val1 > val2) { return -1 } else { return 0 } } this.companyList = companyList1.sort(sortBy) // this.companyList = res.data setTimeout(() => { this.loading = false }, 600) } })
记录自己的采坑之路,需要时方便查找