Take a look at this:
import accountModule from '@/store/modules/account/account';
import otherModule from '@/store/modules/other/other';
export default new Vuex.Store({
modules: {
account: accountModule,
other: otherModule,
}
});
The initialization of data in the other
module is dependent on the account
module due to user-specific settings. For instance, other.state.list
relies on account.state.settings.listOrder
. However, I need the data for the account
module to be retrieved from the server, which involves an asynchronous process. Therefore, when setting up other
, it cannot directly reference account.state.settings.listOrder
as the server response might not have been received yet.
I attempted to export a promise in the accountModule
that resolves with the module itself, but this approach did not work as expected.
import accountModulePromise from '@/store/modules/account/account';
accountModulePromise.then(function (accountMoudle) {
import otherModule from '@/store/modules/other/other';
...
});
However, I encountered an error stating that import
statements must be top-level.
A different method that was unsuccessful involved using await
like so:
let accountModule = await import('@/store/modules/account/account');
import otherModule from '@/store/modules/other/other';
...
This resulted in an error indicating that await
is a reserved word. This is confusing because according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import, this should be a valid operation.