Dmitriy Rudnik
Dmitriy Rudnik

Reputation: 59

dont work ...mapGetters

error [vuex] unknown getter: counter/count`

structure:

store.js

const state = {
    someRootState: 'someRootState'
}

const getters = {
    getRootState: state => state.someRootState
}

import counter from './counter.js'

export default new Vuex.Store({
    state,
    getters,
    modules:{
        counter
    }
})

counter.js

const state = {
    count: 10
}

const getters = {
    getCount: state => state.count
}

export default {
    namespaced: true,
    state,
    getters
}

App.vue

import { mapGetters } from "vuex";

computed: {
    //doesn't work  [vuex] unknown getter: counter/count
    ...mapGetters("counter", [
        "count"
    ]),

    //doesn't work  [vuex] unknown getter: counter/count
    ...mapGetters({
        count: "counter/count"
    }),

    //work
    ...mapGetters(["getRootState"]),

    //work
    ...mapGetters({
        getRootState: "getRootState"
    }),

}

mapStates work's right, mapGetters dont work, please help me to understand

Upvotes: 0

Views: 4344

Answers (1)

Linus Borg
Linus Borg

Reputation: 23968

your getter is called getCount, not count, so the mapGetters call should look like this:

...mapGetters("counter", [
  "getCount"
]),

Upvotes: 5

Related Questions