直接导入商店时,Vuex 商店模块未按正确顺序加载

Vuex store modules not loading in right order when importing store directly

我可能看不太明显,但几个小时后我还是不明白。

问题:当我将我的 Vuex 存储导入非组件文件(api 服务)时,一个模块被正确加载,而另一个模块仅按名称加载,否则为空。

// store.js
import * as collections from "./modules/collections";
import * as auth from "./modules/auth";

export default new Vuex.Store({
  modules: {
    auth,
    collections
  }
});

这两个模块几乎相同。两者都有

export const getters = {}
export const actions = {}
export const mutations = {}
export const state = {}

现在,当我在其他一些非组件文件中 包含商店时,我的 vue 商店看起来像这样:

{"auth":{"authenticated":false,"authToken":"123","loginPending":false,"loginError":{}},"collections":{"collectionsPending":false,"collectionsError":null,"collections":[]}}

现在,当我像这样导入商店以在我的服务中使用它时:

import store from '../store'
// NO OTHER MENTIONS OF STORE, ONLY IMPORTING

突然只有我的授权模块是"empty"

{"auth":{},"collections":{"collectionsPending":false,"collectionsError":null,"collections":[]}}

跟模块加载有关系。

通过添加 console.log 语句加载顺序:

我正在使用 Vue Webpack 样板

唉,抱歉。确实是循环依赖。如果我这样做了,我会收到警告,但没有。

谢谢埃米尔伯杰龙。