Fork me on GitHub

vue中根据当前时间进行排序

  computed: {
    newdataList: function() {
      return this.sortKey(this.dataList, "addtime");
    }
  },
  methods: {
    sortKey(array, key) {
      return array.sort(function(a, b) {
        var x = a[key];
        var y = b[key];
        return x > y ? -1 : x < y ? 1 : 0;
      });
    },
}

this.dataList为数据源


第二种:
Object.keys(sortedList).map(item=>{
sortedList[item] = sortedList[item].sort(x,y)=>{
return Date.parse(x.createTime) - Date.parse(y.createTime)
})
})

 

posted @ 2018-12-10 11:49  欢欢11  阅读(5513)  评论(0编辑  收藏  举报