Created
September 13, 2018 08:28
-
-
Save oomusou/5ad0932d1a754a6dd69de3b0f0dae5f8 to your computer and use it in GitHub Desktop.
This file contains 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: { | |
todos: [ | |
{ task: 'I have a pen', done: false }, | |
{ task: 'I have an apple', done: false }, | |
{ task: 'ahh apple-pen', done: false }, | |
], | |
}, | |
getters: { | |
itemsNotDone(state) { | |
return state.todos.filter(item => !item.done).length; | |
}, | |
itemsDone(state, getters) { | |
return state.todos.length - getters.itemsNotDone; | |
}, | |
taskByIndex: state => index => state.todos[index].task, | |
}, | |
mutations: { | |
addItem(state, payload) { | |
state.todos.push({ task: payload, done: false }); | |
}, | |
finishItem(state, index) { | |
state.todos[index].done = true; | |
}, | |
}, | |
actions: { | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment