简体   繁体   中英

How to import external javascript (which requires jquery) in reactjs

First of all I'm still a newbie in web development. Okay, now to the question. I have these imports:

import $ from 'jquery'; 
window.jQuery = $;
window.$ = $;
global.jQuery = $;
import './assets/js/waves';

How do I properly import an external javascript to reactjs if my external javascript requires jquery?

Because based on what these guys have said:

reactjs, bootstrap and npm import - jQuery is not defined

Are ES6 module imports hoisted?

my imports will be hoisted, which results in my external " ./assets/js/waves " js causing an error.

Uncaught ReferenceError: $ is not defined?

Thanks in advance!

import * as jQuery from 'jquery';

然后,您可以获得jQuery的引用,并且可以根据需要使用它,例如:

window.$ = jQuery;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM