如何通过开发工具控制台使用ES6模块 [英] How to use ES6 modules from dev tools console
本文介绍了如何通过开发工具控制台使用ES6模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
据我了解,如果创建ES6模块,则只能从本身就是模块的代码中导入它。这意味着非模块代码(即内联Javascript)或Chrome开发工具控制台永远无法访问模块中的代码。
As far as I understand it, if I create an ES6 module, I can only import it from code that is itself a module. This means non-module code, i.e. inline Javascript, or the Chrome dev tools console can never access code that is in a module.
是真的吗?有什么办法可以解决,因为它似乎是一个极端的限制。
Is that true? Is there any way around this because it seems like a fairly extreme limitation.
推荐答案
您可以使用动态导入在Chrome的控制台中。
You can use dynamic import within Chrome's console.
import('path/to/module.js').then(m => module = m)
// [doSomething] is an exported function from [module.js].
module.doSomething()
这篇关于如何通过开发工具控制台使用ES6模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文