[Vuejs]-Vuex unable to use modules

1👍

The namespaced setting will cause the actions, mutations and setters of a store to be namespaced based on the module name. The state of a module, however, is always separated off into its own subtree within state, even if namespacing is not being used.

So this won’t work:

...mapState([
   'items'
]),

This is looking for an items property in the root state.

Instead you can use something like:

...mapState({
    items: state => state.itemstore.items
})

You might be tempted to try to write it like this:

...mapState('itemstore', ['items'])

However, passing the module name as the first argument to mapState will only work with namespaced modules.

Leave a comment