[英]How do I access the default export of a module imported via a Webpack dynamic import promise?
Question says it all.问题说明了一切。 Googling returns plenty of examples of ES6 import syntax, but I'm using a Webpack "dynamic import".
谷歌搜索返回了大量 ES6 导入语法的示例,但我使用的是 Webpack “动态导入”。 In the below code, I've shown my consumer file with commented results:
在下面的代码中,我展示了带有注释结果的消费者文件:
Module file:模块文件:
export default class Main {
init() {
console.log("Main init");
}
}
Consumer file:消费者档案:
import(/* webpackChunkName: "main" */ "./main").then(Main => {
init(Main);
});
function init(Main) {
console.log(Main); // "Module"
const main = new Main.Main(); // not a constructor
const main = new Main(); // not a constructor
const main = new Main.getDefault(); // not a constructor
}
I needed to access the module default like:我需要访问模块默认值,例如:
const mainclass = Main.default;
const main = new mainclass();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.