Skip to content

Instantly share code, notes, and snippets.

@oomusou
Created September 13, 2018 08:28
Show Gist options
  • Save oomusou/5ad0932d1a754a6dd69de3b0f0dae5f8 to your computer and use it in GitHub Desktop.
Save oomusou/5ad0932d1a754a6dd69de3b0f0dae5f8 to your computer and use it in GitHub Desktop.
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