你如何从 React 中的 cdn/script 标签导入一个 javascript 包? [英] How do you import a javascript package from a cdn/script tag in React?
本文介绍了你如何从 React 中的 cdn/script 标签导入一个 javascript 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 React 中导入这个 javascript 包
I'd like to import this javascript package in React
<script src="https://cdn.dwolla.com/1/dwolla.js"></script>
但是,没有NPM包,所以我不能这样导入:
However, there is no NPM package, so I can't import it as such:
import dwolla from 'dwolla'
或
import dwolla from 'https://cdn.dwolla.com/1/dwolla.js'
所以每当我尝试
dwolla.configure(...)
我收到一条错误消息,指出 dwolla 未定义.我该如何解决这个问题?
I get an error saying that dwolla is undefined. How do I solve this?
谢谢
推荐答案
进入index.html文件并导入脚本
Go to the index.html file and import the script
<script src="https://cdn.dwolla.com/1/dwolla.js"></script>
然后,在导入dwolla的文件中,将其设置为一个变量
Then, in the file where dwolla is being imported, set it to a variable
const dwolla = window.dwolla;
这篇关于你如何从 React 中的 cdn/script 标签导入一个 javascript 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文