javascript - 在 Chrome 控制台中加载外部库
问题描述
我正在使用 React 和 Redux。在我的减速器中,我正在使用lodash
库。
debugger;
命令停止执行
如果我导入lodash
库
import _ from "../../node_modules/lodash";
或者
import _ from "lodash";
它失败。它无法导入库。运行我的 React 应用程序时没有加载错误。lodash
我想知道您如何在 Google Chrome 控制台中加载外部库(即)?
解决方案
改用动态导入语法,你会得到一个你想要的 Promise。例如,在此页面上:
https://stackoverflow.com/questions/57032914/loading-external-library-in-chrome-console
使用
import('../../foo')
结果是
假设在您自己的网站上,链接是正确的,您需要做的就是调用.then
Promise:
import("../../node_modules/lodash")
.then((_) => {
// do stuff with _
});
(当然,这要求是node_modules
当前页面的祖父目录的子文件夹)
推荐阅读
- python - 如何优化和查找大输入的输出?
- python - Python多线程执行 - 不可扩展
- php - 如何使用 PHP 对大型文本文件进行排序并搜索重复项?
- spring-boot - 如何正确处理 SOAP Web 服务引发的客户端异常
- c# - 实体框架通用方法不接受包含方法
- scala - 如何在不使用可变变量的情况下在 scala 中编写迭代器?
- java - Syncfusion PDF Viewer 中不显示上传的 PDF?
- php - 在 Laravel 中使用中间件缩短 URL 代码
- sql-server - SQL server 函数如何在查询中使用参数
- python - 如何将jpg格式的数据框转换为csv?