因此我在Vue中创建了一个项目,我想遍历所有['monitors']并保存不同的部门。我如何做到最好?
谢谢!



<script>

listOfAllTrips = this.wlData['monitors'][0].lines[0].departures;
listOfAllTrips2 = this.wlData['monitors'][1].lines[0].departures;
listOfAllTrips3 = this.wlData['monitors'][2].lines[0].departures;

</script>

最佳答案

您可以使用函数map和解构分配,如下所示:



let m = [{lines: [{departures: ["Ele", "Stack"]}]}, {lines: [{departures: ["Ele2", "Stack2"]}]}];
let result = m.map(({lines: [departures]}) => departures);
console.log(result);

08-25 22:35