vuex getters call code example
Example 1: vuex access getters from actions
getters: {
getAppData: state => () => {
return state.data;
}
}
actions: {
sendDataToServer({ commit , getters }, payload) {
// call getter
const data = getters.getAppData
}
},
Example 2: vuex mapgetters
import { mapGetters } from 'vuex'
export default {
// ...
computed: {
// mix the getters into computed with object spread operator
...mapGetters([
'doneTodosCount',
'anotherGetter',
// ...
])
}
}