【发布时间】:2019-08-10 18:05:05
【问题描述】:
我在 nuxt 商店中使用多个 vuex 模块,我想在多个模块中使用相同的基本状态,如下所示:
// ~/utils/Sharedstore.js
export default {
state: {
byId: {},
allIds: [],
}
},
// ~store/entities/myEntity.js
import SharedStore from '~/utils/SharedStore';
export const state = () => ({ ...SharedStore.state });
但它不起作用,每当我改变一个状态时,所有模块的状态都会改变。
当我为我的所有模块执行此操作时:
// ~store/entities/myEntity.js
export const state = () => ({
byId: {},
allIds: [],
});
问题是我想将重复的基本状态放在一个地方(SharedStore.state)。为什么导入时无法正常工作,我该如何解决?
【问题讨论】: