Files
ghibli-api/store/vehicles/index.js

26 lines
534 B
JavaScript

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: ${e.message}`);
}
}
};
export const getters = {
vehicle: state => state.vehicle
};