Skip to content

Instantly share code, notes, and snippets.

@KatarinaT
Created September 19, 2022 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KatarinaT/10f788afae9c7a1cb037ce5377366d2f to your computer and use it in GitHub Desktop.
Save KatarinaT/10f788afae9c7a1cb037ce5377366d2f to your computer and use it in GitHub Desktop.
>>>>> actions.js
###############################
import Api from "@/helpers/api";
export const actions = {
async loadEvents(context, payload) {
let result;
try {
result = (await Api.getEventsList(payload.page, payload.perPage))?.data;
} catch (e) {
console.error("events list getting error: ", e);
result = [];
}
context.commit('setEvents', result);
},
async loadEventsByDates(context, payload) {
let result;
try {
result = (await Api.getEventsByFilters(payload.start, payload.end))?.data;
} catch (e) {
console.error("events list by dates getting error: ", e);
}
context.commit('setEvents', result);
}
}
>>>>> mutations.js
###############################
export const mutations = {
setEvents(state, eventList) {
state.events = eventList;
}
};
>>>>> getters.js
###############################
import {EventConverter} from "@/helpers/eventConverter";
export const getters = {
getEvents: state => {
return EventConverter.getConvertedEvents(state.events);
}
}
>>>>> index.js
###############################
import Vue from 'vue';
import Vuex from 'vuex';
import {actions} from './action';
import {getters} from './getters';
import {mutations} from './mutations';
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
events: []
},
actions,
getters,
mutations
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment