Nuxt + Vuex-如何将Vuex模块分解为单独的文件?

JavaScript Vue.js

Davaid前端Harry

2020-03-20

在Nuxt文件(在这里),它说:“你可以在模块文件有可能分解为单独的文件:state.jsactions.jsmutations.jsgetters.js。”

我似乎无法找到如何做到这一点的任何例子-大量的打破Vuex店在根级进入的state.jsactions.jsmutations.jsgetters.js,和为单独的模块文件,而是打破了模块本身倒没什么。

所以目前我有:

     ├── assets
     ├── components
     └── store
           ├── moduleOne.js
           ├── moduleTwo.js
           └── etc...

我想拥有的是:

     ├── assets
     ├── components
     └── store
           └── moduleOne
                 └── state.js
                 └── getters.js
                 └── mutations.js
                 └── actions.js
           └── moduleTwo
                └── etc...

要尝试这一点,/store/moduleOne/state.js我有:

export const state = () => {
    return {
        test: 'test'
    }
};

并且/store/moduleOne/getters.js我有:

export const getters = {
    getTest (state) {
        return state.test;
    }
}

在我的组件中,我正在使用 $store.getters['moduleOne/getters/getTest']

However using the debugger and Vue devtools, it seems like state isn't accessible in the getters file - it seems to be looking for a state in the local file, so state.test is undefined.

Attempting to import state from my state.js file into my getters.js file doesn't seem to work either.

Does anyone have an example of how they've managed to break the store down like this in Nuxt?

第2464篇《Nuxt + Vuex-如何将Vuex模块分解为单独的文件?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android