看一下这个:
import accountModule from '@/store/modules/account/account';
import otherModule from '@/store/modules/other/other';
export default new Vuex.Store({
modules: {
account: accountModule,
other: otherModule,
}
});
数据的初始化other取决于account模块,因为account模块具有用户特定的设置。假设other.state.list取决于account.state.settings.listOrder。但是,我希望account模块的数据来自服务器。这是异步的。因此,当other尝试进行设置时,它不能仅尝试进行引用,account.state.settings.listOrder因为来自服务器的响应可能还没有回来。
我尝试导出承诺在accountModule与模块本身能解决。但是这种方法似乎行不通。
import accountModulePromise from '@/store/modules/account/account';
accountModulePromise.then(function (accountMoudle) {
import otherModule from '@/store/modules/other/other';
...
});
这给我一个错误,说import语句必须是顶级的。
以下内容也不起作用:
let accountModule = await import '@/store/modules/account/account';
import otherModule from '@/store/modules/other/other';
...
这给我一个错误,说这await是一个保留字。不过我很困惑,因为https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import表示我应该能够做到。
繁星点点滴滴
红颜莎娜
相关分类