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