【问题标题】:Nuxt.js custom store folderNuxt.js 自定义存储文件夹
【发布时间】:2019-01-29 19:15:31
【问题描述】:

我尝试更改默认情况下 nuxt.js 使用的 vuex 存储路径。我希望我的商店路径是“modules/my-module/store/store.js”。有什么办法可以做到这一点吗?或者我可以以某种方式将我的模块存储从 nuxt 模块文件添加到现有存储?

【问题讨论】:

    标签: vue.js vuex nuxt.js


    【解决方案1】:

    是的,您可以使用registerModule 函数动态注册一个商店模块。

    假设你有你的 my-module 模块,里面有你的index.vue 文件。在该文件中,您可以像这样注册模块的商店:

    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
      },
    };
    

    我向您推荐这篇 medium 文章,它建议了一些好的 vue.js 应用程序结构,包括展示如何注册私有模块的存储模块

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多