上代码
let list = [{
id: 0,
name: '充值消费金',
time: 1653533103,
money: 200
}, {
id: 0,
name: '充值消费金',
time: 1653189651,
money: 200
}, {
id: 1,
name: '充值消费金',
time: 1650941103,
money: 200
}, {
id: 1,
name: '充值消费金',
time: 1650941103,
money: 200
}],
alltimeList = [];
list.map(item => {
let m = this.$mUtils.formatTime(item.time, 'Y-M');
let timeList = item //
let newTimeList = {
time: '',
timeList: []
}
newTimeList.time = m
newTimeList.timeList.push(timeList)
let falg = false;
//判断相同重组
alltimeList.map((val, num) => {
if (m == val.time) {
val.timeList.push(timeList)
falg = true
return
}
})
//没有添加新的日期数组
if (!falg) {
alltimeList.push(newTimeList)
}
})
this.list = alltimeList;
最后来张效果图吧
以上有所不理解可以小程序联系我