作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 React 和 Redux。在我的 Reducer 中,我正在使用 lodash
库。
调试器;
命令停止执行
如果我导入lodash
库
从“../../node_modules/lodash”导入 _;
或
从“lodash”导入 _;
它失败了。它无法导入库。当我运行我的 React 应用程序时没有加载错误。我想知道如何在 Google Chrome 控制台中加载外部库(即 lodash
)?
最佳答案
改用动态导入语法,你会得到一个包含你想要的内容的 Promise。例如,在此页面上:
https://stackoverflow.com/questions/57032914/loading-external-library-in-chrome-console
使用
import('../../foo')
结果
假设在您自己的网站上,链接是正确的,您需要做的就是在 Promise 上调用 .then
:
import("../../node_modules/lodash")
.then((_) => {
// do stuff with _
});
(当然,这需要node_modules
是当前页面祖父目录的子文件夹)
关于javascript - 在 Chrome 控制台中加载外部库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57032914/
我是一名优秀的程序员,十分优秀!