I seem to be unable to find a way to successfully access getters from within a module, the getter requires a parameter in order to search an object within state of the same module.
For example:
// store/todo.js
export const getters = {
getTodoById: (state) => (id) => {
return state.todos.find(todo => todo.id === id)
}
}
// a component.vue
store.getters.todos.getTodoById(2)
I get the response:
Cannot read property 'getTodoById' of undefined
I assume this should be possible? Where might I be going wrong?
Can you try this? store.getters['todo/getTodoById'](2)
Edit: I think you need to change todos in todo, vue check the file name IIRC
store.getters.todo.getTodoById(2)
That worked! Thank you very much, been trawling docs for ages.
This question has been resolved by @microcipcip, see answer.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Can you try this?
store.getters['todo/getTodoById'](2)Edit: I think you need to change
todosintodo, vue check the file name IIRCstore.getters.todo.getTodoById(2)