40 lines
900 B
JavaScript
40 lines
900 B
JavaScript
export const state = () => ({
|
|
list: [],
|
|
location: {}
|
|
});
|
|
|
|
export const mutations = {
|
|
setList: (state, locations) => {
|
|
state.list = locations;
|
|
},
|
|
setLocation: (state, location) => {
|
|
state.location = location;
|
|
}
|
|
};
|
|
|
|
export const actions = {
|
|
async getList({ commit }) {
|
|
try {
|
|
const locations = await this.$axios.$get(
|
|
"/api/locations?fields=id,name,climate,terrain,surface_water,residents,films"
|
|
);
|
|
commit("setList", locations);
|
|
} catch (e) {
|
|
throw Error(`API Error occurred: ${e.message}`);
|
|
}
|
|
},
|
|
async getLocation({ commit }, id) {
|
|
try {
|
|
const location = await this.$axios.$get(`/api/locations/${id}`);
|
|
commit("setLocation", location);
|
|
} catch (e) {
|
|
throw Error(`API Error occurred: ${e.message}`);
|
|
}
|
|
}
|
|
};
|
|
|
|
export const getters = {
|
|
list: state => state.list,
|
|
location: state => state.location
|
|
};
|