在Nuxt文件(在这里),它说:“你可以在模块文件有可能分解为单独的文件:state.js
,actions.js
,mutations.js
和getters.js
。”
我似乎无法找到如何做到这一点的任何例子-大量的打破Vuex店在根级进入的state.js
,actions.js
,mutations.js
和getters.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?