Skip to content

Instantly share code, notes, and snippets.

@harrybeckwith
Created July 24, 2019 12: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 harrybeckwith/54afd2e8afb510741efad98a5fd2bb2d to your computer and use it in GitHub Desktop.
Save harrybeckwith/54afd2e8afb510741efad98a5fd2bb2d to your computer and use it in GitHub Desktop.
mutations and actions
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
categories: ['travel', 'fun', 'social', 'work', 'other'],
events: [],
},
getters: {
cat: state => {
return state.categories;
},
getEventById: state => id => {
return state.events.find(event => event.id === id);
},
events: state => {
return state.events;
},
},
mutations: {
ADD_EVENT(state, event) {
state.events.push(event);
},
},
actions: {
createEvent({ commit }, event) {
commit('ADD_EVENT', event);
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment