gpt4 book ai didi

javascript - 在 Chrome 控制台中加载外部库

转载 作者:行者123 更新时间:2023-11-30 19:24:46 24 4
gpt4 key购买 nike

我正在使用 React 和 Redux。在我的 Reducer 中,我正在使用 lodash 库。

调试器;命令停止执行

如果我导入lodash

从“../../node_modules/lodash”导入 _;

从“lodash”导入 _;

enter image description here

它失败了。它无法导入库。当我运行我的 React 应用程序时没有加载错误。我想知道如何在 Google Chrome 控制台中加载外部库(即 lodash)?

最佳答案

改用动态导入语法,你会得到一个包含你想要的内容的 Promise。例如,在此页面上:

https://stackoverflow.com/questions/57032914/loading-external-library-in-chrome-console

使用

import('../../foo')

结果

enter image description here

假设在您自己的网站上,链接是正确的,您需要做的就是在 Promise 上调用 .then:

import("../../node_modules/lodash")
.then((_) => {
// do stuff with _
});

(当然,这需要node_modules是当前页面祖父目录的子文件夹)

关于javascript - 在 Chrome 控制台中加载外部库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57032914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com