Nuxt.js: Accessing Vuex getters with parameters

Created on 30 Jan 2018  路  4Comments  路  Source: nuxt/nuxt.js

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)

Most helpful comment

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)

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pehbehbeh picture pehbehbeh  路  3Comments

vadimsg picture vadimsg  路  3Comments

gary149 picture gary149  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

surmon-china picture surmon-china  路  3Comments