rad*_*per 5 arrays sorting datetime vue.js
是否有按日期或格式化日期对数组进行排序的功能或方法?
var sortbydate = new Vue({
el: '#sortbydate',
data: {
items: [
{ codeName: 'Looper', date: '25.03.1980' },
{ codeName: 'Sweetze', date: '25.03.1981' },
{ codeName: 'Lycon', date: '01.08.1991' }
]
}
})
Run Code Online (Sandbox Code Playgroud)
<ul id="sortbydate">
<li v-for="(item, index) in items" style="list-style:none">
{{ index }} - {{ item.codeName }}
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
只是必须这样做,所以我会写下最简单的解决方案:
...
computed: {
sortedItems: function() {
this.items.sort( ( a, b) => {
return new Date(a.date) - new Date(b.date);
});
return this.items;
}
}
...
Run Code Online (Sandbox Code Playgroud)
或者如果你想要一个班轮
...
computed: {
sortedItems: function() {
return this.items.sort((a, b) => new Date(a.date) - new Date(b.date))
}
}
...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10267 次 |
最近记录: |