我有一个类在Typescript中,我试图使一个同步导入,但导入是异步的。我正在尝试这个。
--------------100 lines of code--------------------
import('../../../x/y/z').then((x) => {
alert('Component')
});
--------------100 lines of code----------------------
但是,使用这种方法的警报被打印在最后,即后200行得到执行(异步,因为内部的Promise被使用),但我想执行它在给定的串行顺序。
谢谢,谢谢
你只需要提前导入,从导入的模块中调用同步函数就可以了。
// hello.js
export default function hello() { return "Hello, world!" }
// index.js
import hello from "./hello"
hello()