错误[vuex] unknown getter:counter / count`
const state = {
someRootState: 'someRootState'
}
const getters = {
getRootState: state => state.someRootState
}
import counter from './counter.js'
export default new Vuex.Store({
state,
getters,
modules:{
counter
}
})
const state = {
count: 10
}
const getters = {
getCount: state => state.count
}
export default {
namespaced: true,
state,
getters
}
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工作正确,mapGetters不工作,请帮助我理解
答案 0 :(得分:3)
您的getter名为getCount
,而非count
,因此mapGetters
调用应如下所示:
...mapGetters("counter", [
"getCount"
]),