Javascript 如何在Vue中对包含2个字段的数组进行排序?
我有一张桌子: 我用这个,我只能用一个字段来排序 我想做的是使用Javascript 如何在Vue中对包含2个字段的数组进行排序?,javascript,arrays,sorting,vue.js,computed-properties,Javascript,Arrays,Sorting,Vue.js,Computed Properties,我有一张桌子: 我用这个,我只能用一个字段来排序 我想做的是使用score和time\u consumered字段按降序对数组进行排序。分数越高,花费的时间越短,排名越高 在上面的例子中,顺序应该如下所示 1. 12 | 10141 2. 5 | 15233 3. 5 | 16233 4. 3 | 11495 我使用了库中的orderBy筛选器,但我只能使用 v-for="u in orderBy(users, 'score', -1)" 有没有更简单的方法?任何帮助都将不胜感激。使用计算
score
和time\u consumered
字段按降序对数组进行排序。分数越高,花费的时间越短,排名越高
在上面的例子中,顺序应该如下所示
1. 12 | 10141
2. 5 | 15233
3. 5 | 16233
4. 3 | 11495
我使用了库中的orderBy筛选器,但我只能使用
v-for="u in orderBy(users, 'score', -1)"
有没有更简单的方法?任何帮助都将不胜感激。使用计算值对分数进行排序
console.clear()
常数分数=[
{
得分:3分,
所用时间:11495
},
{
得分:5分,
所用时间:16233
},
{
得分:5分,
所用时间:15233
},
{
得分:12分,
所用时间:10141
},
]
新Vue({
el:“应用程序”,
数据:{
分数
},
计算:{
分类核心(){
常量排序器=(a,b)=>b.score-a.score | | a.time_消耗-b.time_消耗
返回此.scores.sort(分拣机)
}
}
})
{{score.score}
{{score.time}