Namespaced module

The namespaced option tells Vuex to also add the 'maps/' namespace before all the getter, mutation, and action types of the module. It will also add them to the commit and dispatch calls inside the namespaced module.

Let's add a few getters that will be used by the BlogMap component:

getters: {
center: state => state.center,
zoom: state => state.zoom,
},

The maps/center and the maps/zoom getters will be added to the store. To read them, you could do:

this.$store.getters['maps/center']

With the getter helper:

mapGetters({
center: 'maps/center',
zoom: 'maps/zoom',
})

You can also specify a namespace parameter:

...mapGetters('maps', [
'center',
'zoom',
]),
...mapGetters('some/nested/module', [
// ...
]),

The last way to do it is to generate helpers based on a specific namespace with the createNamespacedHelpers method:

import { createNamespacedHelpers } from vuex
const { mapGetters } = createNamespacedHelpers('maps')

export default {
computed: mapGetters([
'center',
'zoom',
]),
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.196.211