getters store vuejs code example
Example 1: vuex getter root state
const getters = {
getParams: (state, getters, rootState) => {
return rootState.route.params
}
}
Example 2: vue js getter
const store = new Vuex.Store({
state: {
todos: [
{ id: 1, text: '...', done: true },
{ id: 2, text: '...', done: false }
]
},
getters: {
doneTodos: state => {
return state.todos.filter(todo => todo.done)
}
}
});
console.log(store.state.getters.doneTodos);
// -> [{ id: 1, text: '...', done: true }]