Create vuex modules for Films/Vehicles/Locations/People + Test adaptation
This commit is contained in:
37
store/films/index.js
Normal file
37
store/films/index.js
Normal file
@@ -0,0 +1,37 @@
|
||||
export const state = () => ({
|
||||
list: [],
|
||||
film: {}
|
||||
});
|
||||
|
||||
export const mutations = {
|
||||
setList: (state, films) => {
|
||||
state.list = films;
|
||||
},
|
||||
setFilm: (state, film) => {
|
||||
state.film = film;
|
||||
}
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
async getList({ commit }) {
|
||||
try {
|
||||
const films = await this.$axios.$get("/api/films");
|
||||
commit("setList", films);
|
||||
} catch (e) {
|
||||
throw Error("API Error occurred.");
|
||||
}
|
||||
},
|
||||
async getFilm({ commit }, id) {
|
||||
try {
|
||||
const film = await this.$axios.$get(`/api/films/${id}`);
|
||||
commit("setFilm", film);
|
||||
} catch (e) {
|
||||
throw Error("API Error occurred.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getters = {
|
||||
list: state => state.list,
|
||||
film: state => state.film
|
||||
};
|
||||
Reference in New Issue
Block a user