我需要做类似的事情:
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"的链接将我转储到已弃用的文档页面.
我想在<script>手动document.createElement,然后到appendChild了audio一个每次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)中销毁和重新创建组件的首选方法是什么?