Created
July 23, 2019 09:21
-
-
Save harrybeckwith/2cb75f97cdb289e86753f7e402c8b5ea to your computer and use it in GitHub Desktop.
store js file with state and getters set up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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