[英]Why does async + await return AsyncFunction?
const config = async () => {
return await import("../test");
}
console.log(config);
../test ../测试
export const config = {
value1: 1,
value1: 2,
};
I want config
in../test but this returns [AsyncFunction: config]
.我想要
config
in../test 但这会返回[AsyncFunction: config]
。
async () => {}
is a function declaration. async () => {}
是一个 function 声明。 So you assigned config
to a function.因此,您将
config
分配给 function。
You have to call that function, and await
the result, in order to get the value you want.您必须调用该 function,并
await
结果,以获得您想要的值。
console.log(await config());
But are you sure you want a dynamic import here?但是您确定要在此处进行动态导入吗?
Because this should do the same thing without any headaches at all.因为这应该做同样的事情而不会让人头疼。
import { config } from "../test";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.