如何在 reactjs 中导入外部 javascript(需要 jquery) [英] How to import external javascript (which requires jquery) in reactjs

查看:72
本文介绍了如何在 reactjs 中导入外部 javascript(需要 jquery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我仍然是 Web 开发的新手.好的,现在该问题了.我有这些进口:

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';

如果我的外部 javascript 需要 jquery,我如何正确地将外部 javascript 导入到 reactjs?

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 和 npm 导入 - jQuery 未定义

是否提升了 ES6 模块导入?

我的导入将被提升,这导致我的外部./assets/js/waves"js 导致错误.

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

Uncaught ReferenceError: $ is not defined?

提前致谢!

推荐答案

import * as jQuery from 'jquery';

然后你有一个 jQuery 的引用,你可以用它做你喜欢做的事情,例如:

Then you have a reference of jQuery and you may do with it what you like, for instance:

window.$ = jQuery;

这篇关于如何在 reactjs 中导入外部 javascript(需要 jquery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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