Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

html - How do you import a javascript package from a cdn/script tag in React?

I'd like to import this javascript package in React

<script src="https://cdn.dwolla.com/1/dwolla.js"></script>

However, there is no NPM package, so I can't import it as such:

import dwolla from 'dwolla'

or

import dwolla from 'https://cdn.dwolla.com/1/dwolla.js'

so whenver I try

dwolla.configure(...)

I get an error saying that dwolla is undefined. How do I solve this?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Go to the index.html file and import the script

<script src="https://cdn.dwolla.com/1/dwolla.js"></script>

Then, in the file where dwolla is being imported, set it to a variable

const dwolla = window.dwolla;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...