Add basic Vue logic to Vehicles/Locations/People

This commit is contained in:
2020-12-18 15:23:45 +01:00
parent e7e6ed91f8
commit d8cfe69fa0
7 changed files with 280 additions and 7 deletions

View File

@@ -1,6 +1,9 @@
export const state = () => ({
films: [],
film: {}
film: {},
location: {},
person: {},
vehicle: {}
});
export const mutations = {
@@ -9,6 +12,15 @@ export const mutations = {
},
setFilm: (state, film) => {
state.film = film;
},
setLocation: (state, location) => {
state.location = location;
},
setPerson: (state, person) => {
state.person = person;
},
setVehicle: (state, vehicle) => {
state.vehicle = vehicle;
}
};
@@ -28,6 +40,30 @@ export const actions = {
} catch (e) {
throw Error("API Error occurred.");
}
},
async getLocation({ commit }, id) {
try {
const location = await this.$axios.$get(`/api/locations/${id}`);
commit("setLocation", location);
} catch (e) {
throw Error("API Error occurred.");
}
},
async getPerson({ commit }, id) {
try {
const person = await this.$axios.$get(`/api/people/${id}`);
commit("setPerson", person);
} catch (e) {
throw Error("API Error occurred.");
}
},
async getVehicle({ commit }, id) {
try {
const vehicle = await this.$axios.$get(`/api/vehicles/${id}`);
commit("setVehicle", vehicle);
} catch (e) {
throw Error("API Error occurred.");
}
}
};