vuex namespaced mapState with multiple modules
Use the spread operator:
computed: {
...mapState('user', ['addresses', 'creditCards']),
...mapState('vendor', ['products', 'ratings'])
}
This is from the vuex docs, you can do it all within one ...mapState({})
. Documentation
computed: {
...mapState({
a: state => state.some.nested.module.a,
b: state => state.some.nested.module.b
})
},
Edit 2019
You can also pass a path to your nested module and make the module references cleaner (thanks @gijswijs)
computed: {
...mapState('some/nested/module', {
a: state => state.a,
b: state => state.b
})
},