Load Locations/People/Vehicles from layout on app load

This commit is contained in:
2020-12-21 22:06:36 +01:00
parent 5bab5b2041
commit 2e35d86e1a
3 changed files with 42 additions and 5 deletions

View File

@@ -1,18 +1,31 @@
export const state = () => ({
list: [],
vehicle: {}
});
export const mutations = {
setList: (state, vehicles) => {
state.list = vehicles;
},
setVehicle: (state, vehicle) => {
state.vehicle = vehicle;
}
};
export const actions = {
async getVehicle({ commit }, { id, callback = false }) {
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}`);
if (callback) return vehicle;
commit("setVehicle", vehicle);
} catch (e) {
throw Error(`API Error occurred: ${e.message}`);
@@ -21,5 +34,6 @@ export const actions = {
};
export const getters = {
list: state => state.list,
vehicle: state => state.vehicle
};