Home

Issue: 2723

Accessing Vuex getters with parameters

[issue link]

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?

This question is available on Nuxt.js community (#c2364)