你如何从React中的cdn/script标签导入一个javascript包? [英] How do you import a javascript package from a cdn/script tag in React?

查看:786
本文介绍了你如何从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆