Nuxt.js: Vuex Store with modules bug with mapGetters

Created on 12 Feb 2017  路  4Comments  路  Source: nuxt/nuxt.js

Using separate files for Vuex Store in Nuxt.js
Pretty sure there is a bug in module getters _(or I'm dummy which also happens a lot)_

This works... ( in store/project.js )

{{ selected }}
...
computed: {
  selected () {
        return this.$store.state.projects.selected
  }...
}

this does not...

computed: {
     ...mapGetters('projects', ['selected'])
  }...
}

nor does this...

      ...mapGetters({
        selected: 'projects/selected'
      }),

nor this...

      ...mapGetters(['projects/selected']),

PS my getter is ... ( store.projects.js )

export const getters = {
  selected () {
    return state.selected
  }

I've gotten this to work in plain vue/vuex so maybe I'm just messing up the NuxtJS syntax?

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

Most helpful comment

Hi @enricribas

I just updated the vuex-store-modules to use the getters.

It should work like this:

store/projects.js:

export const getters = {
  selected (state) {
    return state.selected
  }
}

And in your component:

computed: {
  ...mapGetters({
    selected: 'projects/selected'
  })
}

All 4 comments

Hi @enricribas

I just updated the vuex-store-modules to use the getters.

It should work like this:

store/projects.js:

export const getters = {
  selected (state) {
    return state.selected
  }
}

And in your component:

computed: {
  ...mapGetters({
    selected: 'projects/selected'
  })
}

damn sorry. I was missing the state in the getter. Strange I didn't see an error.

what if i want to pass parameters to getter method ?

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

shyamchandranmec picture shyamchandranmec  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

mikekidder picture mikekidder  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

jaredreich picture jaredreich  路  3Comments