0👍
✅
flights
is your main array that holds the flights objects. It would be much easier to just use a getter (or a couple of getters) to get your filtered data, without having to mutate the state.
getters: {
getFlightsByTripClass: (state) => (tripClass) => {
return state.flights.filter(flight => flight.trip_class === tripClass);
}
}
To use this getter in your Vue component, you can access it using this.$store.getters
:
computed: {
filteredFlights() {
return this.$store.getters.getFlightsByTripClass(1);
}
}
Also, for good measure, make sure to follow the camel case convention for your variables. Use numberOfChange
, instead of number_of_change
.
Source:stackexchange.com