Create vuex modules for Films/Vehicles/Locations/People + Test adaptation
This commit is contained in:
25
store/vehicles/index.js
Normal file
25
store/vehicles/index.js
Normal file
@@ -0,0 +1,25 @@
|
||||
export const state = () => ({
|
||||
vehicle: {}
|
||||
});
|
||||
|
||||
export const mutations = {
|
||||
setVehicle: (state, vehicle) => {
|
||||
state.vehicle = vehicle;
|
||||
}
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async getvehicle({ commit }, { id, callback = false }) {
|
||||
try {
|
||||
const vehicle = await this.$axios.$get(`/api/vehicles/${id}`);
|
||||
if (callback) return vehicle;
|
||||
commit("setVehicle", vehicle);
|
||||
} catch (e) {
|
||||
throw Error("API Error occurred.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
vehicle: state => state.vehicle
|
||||
};
|
||||
Reference in New Issue
Block a user