vue中数组排序
2018-08-07 本文已影响21人
前端_周瑾
<template>
<div>
<li v-for="item in list">
<p>
<span>{{item.time}}</span>
<span>{{item.name}}</span>
</p>
</li>
</div>
</template>
<script>
import axios from 'axios'
export default {
name: "arr-sort",
data(){
return{
list: [
{time: '2018-06-01 14:11:29',name:'1'},
{time: '2018-06-05 14:11:29',name:'5'},
{time: '2018-06-06 14:11:29',name:'6'},
{time: '2018-06-02 14:11:29',name:'2'},
{time: '2018-06-03 14:11:29',name:'3'},
{time: '2018-06-04 14:11:29',name:'4'},
{time: '2018-06-07 14:11:29',name:'7'},
]
}
},
created(){
this.list.sort(function (a,b) {
// 按照时间降序
return Date.parse(b.time) - Date.parse(a.time)
})
}
}
</script>
<style scoped>
</style>