Closed rollinson9 closed 5 years ago
Hello sorry for the late reply.
this.biggerNum
is undefined because you're trying to access a getter from another getter.
Remember Vuex getters only have access to the state
object.
Hi @michaelolof,
It's no problem, thank you for the reply!
I'm not sure if that's right? I've had no problem using the normal vuex way of access getters within getters. The first argument is state, but then the second argument is generally the getters object. Within namespaced modules, the 3rd and 4th argument are rootState and rootGetters
You should be able to see what I mean here: https://vuex.vuejs.org/guide/getters.html#property-style-access
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)
},
doneTodosCount: (state, getters) => {
return getters.doneTodos.length
}
}
})
https://vuex.vuejs.org/guide/modules.html#module-local-state
const moduleA = {
// ...
getters: {
sumWithRootCount (state, getters, rootState, rootGetters) {
return state.count + rootState.count
}
}
}
I hope this helps to explain what I mean, if this isn't a feature you're looking to implement then please let me know.
Thank you for you help!
We've also run into this problem. We make use of the 2nd getter param fairly extensively.
Any chance you'd consider (reopening this issue, and) fixing this or accepting a PR which adds support for it?
To a lesser extend we also use rootState and rootGetters, but we could probably live without that.
Hi,
I've been looking for a library like this for a while, it makes so much more sense to me! I've gone through the documentation (and tests) and I believe I should be able to access the store in getters and additional access other getters.
Apologies if I've missed a step, but I can recreate this issue with namespaced modules below.
Thanks!