lynx: requireModuleAsync() static method
引入一个模块,类似 requireModule 函数,但是加载过程是异步进行的,加载过程中会执行其他 JavaScript 代码。
requireModuleAsync 加载的模块需要使用特定的格式,可以使用 @lynx-js/runtime-wrapper-webpack-plugin 来生成可以被 requireModuleAsync 加载的模块。
语法
参数
path
模块路径,可以是远程路径,也可以是模板内的路径。
callback
模块加载完成或失败后调用的回调函数。
- 如果加载过程中发生了错误,一个
error对象会作为第一个参数被传入 - 其他情况下,
null会作为第一个参数被传入,模块的导出值会作为第二个参数被传入
返回值
无(undefined)。
异常
当出现网络错误,或者模块执行失败时,requireModuleAsync 会将异常作为第一个参数传给回调函数。
示例
加载远程资源
Promisify
兼容性
LCD tables only load in the browser