【发布时间】:2019-09-22 16:44:30
【问题描述】:
我有一个带有模块状态的 nuxt 应用程序:
- 商店
- index.js、state.js、mutations.js、actions.js、getters.js
- 模块
- 帖子
- index.js、state.js、mutations.js、actions.js、getters.js
在 Store/index.js 我有:
import state from './state'
import * as actions from './actions'
import * as mutations from './mutations'
import * as getters from './getters'
import posts from './modules/posts'
export default {
state,
getters,
mutations,
actions,
modules: {
posts
}
}
在 Store/state.js 我有:
export default () => ({
test: null
})
在 Store/Modules/Posts/index.js 我有:
import state from './state'
import * as actions from './actions'
import * as mutations from './mutations'
import * as getters from './getters'
export default {
namespaced: true,
state,
getters,
mutations,
actions
}
在 Store/Modules/Posts/state.js 我有:
export default () => ({
dialog: false,
test: false
})
我的商店现在已经复制了 getter、action 等所有内容。 是不是应该这样?我是否应该或不应该如何使用商店? 当我从基础 inldex.js 中删除模块时,我拥有一切之一,但是,一切都是未定义的。
存储输出示例:
【问题讨论】: