相关疑难解决方法(0)

如何有条件地导入ES6模块?

我需要做类似的事情:

if (condition) {
    import something from 'something';
}
// ...
if (something) {
    something.doStuff();
}
Run Code Online (Sandbox Code Playgroud)

上面的代码没有编译; 它抛出SyntaxError: ... 'import' and 'export' may only appear at the top level.

我试着用System.import如图所示这里,但我不知道在哪里System的来了.是不是最终被接受的ES6提案?该文章中"programmatic API"的链接将我转储到已弃用的文档页面.

javascript module ecmascript-6

167
推荐指数
7
解决办法
9万
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

module ×1