相关疑难解决方法(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万
查看次数

ReferenceError:Svelte 3中未定义文档

我想在<script>手动document.createElement,然后到appendChildaudio一个每次eventListener被调用来取代它。一切都能在浏览器中正常运作,除了加载页面时发生的真正快速错误外,持续时间不到100ms。终端中也有错误

ReferenceError: document is not defined
    at Object (webpack:///./src/components/Record/Component.svelte?:26:17)
Run Code Online (Sandbox Code Playgroud)

似乎在文档还没有准备好但后来还可以的时候调用了上面的方法,该如何解决?或者在Svelte world(Sapper)中销毁和重新创建组件的首选方法是什么?

svelte

1
推荐指数
2
解决办法
787
查看次数

标签 统计

ecmascript-6 ×1

javascript ×1

module ×1

svelte ×1