去重方法(根据id去重):
filterById(arr) {
return arr.filter((item, index, self) => {
return self.findIndex((cc) => cc.id == item.id) === index;
});
},
使用:
let allData = [
{ id: 1, name: "b" },
{ id: 1, name: "b" },
{ id: 2, name: "a" },
{ id: 2, name: "a" },
{ id: 2, name: "a" },
];
this.filterById(allData); // [{"id": 1,"name": "b"},{"id": 2,"name": "a"}]