Skip to content

Instantly share code, notes, and snippets.

@harrybeckwith
Created July 23, 2019 09:21
Show Gist options
  • Select an option

  • Save harrybeckwith/2cb75f97cdb289e86753f7e402c8b5ea to your computer and use it in GitHub Desktop.

Select an option

Save harrybeckwith/2cb75f97cdb289e86753f7e402c8b5ea to your computer and use it in GitHub Desktop.
store js file with state and getters set up
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
user: { id: 'aaa', name: 'Adsasas' },
events: [
{
id: 1,
title: 'title one',
organizer: 'a'
},
{
id: 2,
title: 'title two',
organizer: 'b'
},
{
id: 3,
title: 'title three',
organizer: 'c'
}
],
categories: [
'sustainability',
'nature',
'animal welfare',
'housing',
'education',
'food',
'community'
]
},
mutations: {},
actions: {},
getters: {
catLength: state => {
return state.categories.length
},
doneToDos: state => {
return state.todos.filter(todo => todo.done)
},
activeTodosCount: state => {
return state.todos.filter(todo => !todo.done).length
},
getEventById: state => id => {
return state.events.find(event => event.id === id)
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment