export const state = () => ({ list: [], vehicle: {} }); export const mutations = { setList: (state, vehicles) => { state.list = vehicles; }, setVehicle: (state, vehicle) => { state.vehicle = vehicle; } }; export const actions = { async getList({ commit }) { try { const vehicles = await this.$axios.$get( "/api/vehicles?fields=id,name,description,vehicle_class,length,pilot,films" ); commit("setList", vehicles); } catch (e) { throw Error(`API Error occurred: ${e.message}`); } }, async getVehicle({ commit }, id) { try { const vehicle = await this.$axios.$get(`/api/vehicles/${id}`); commit("setVehicle", vehicle); } catch (e) { throw Error(`API Error occurred: ${e.message}`); } } }; export const getters = { list: state => state.list, vehicle: state => state.vehicle, getVehiclesByFilmId: state => id => { return state.list.filter(vehicle => vehicle.films.split("/")[4] === id); } };