I tried to change vuex store path that is used by nuxt.js by default. I want my store path to be 'modules/my-module/store/store.js'. Is there any way I can do this? Or maybe I can somehow add my module store to existing store from nuxt module file?
Yes, you can register a store module dynamically using the registerModule function.
Let's say you have your my-module module and inside you have your index.vue file. Inside that file you can register you module's store like this:
import store from './store'; //import your module store
export default {
name: 'my-module',
computed: {
...
},
created() {
this.$store.registerModule('myModuleStore', store);
},
mounted() {
this.$store.dispatch('myModuleStore/someAction'); //example of action for your module's store
},
};
I recommend you this medium article that suggests some good vue.js application structures, including store modules where it shows how to register a private module
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With