React JavaScript是否支持jQuery? [英] Does React JavaScript support jQuery?

查看:143
本文介绍了React JavaScript是否支持jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在React Js中使用jQuery,但是它显示了"$" is undefined.是否需要安装一些软件包,或者React不支持jQuery.

解决方案

对于您的特定问题,请尝试通过npm安装jQuery.

npm i jquery --save

yarn add jquery

然后,在您的模块中...

import $ from 'jquery'

话虽如此,将jQuery和React一起使用并不是一件容易的事. React没有意识到在虚拟DOM之外所做的更改,而jQuery直接操作标准DOM.

有关如何解决此问题的文章此处

I'm trying to use jQuery in React Js but it shows that "$" is undefined. Is there some package I need to install or does React does not support jQuery.

解决方案

For your specific problem, try installing jQuery via npm.

npm i jquery --save

or

yarn add jquery

Then, in your modules...

import $ from 'jquery'

With that said, it's no easy thing to use jQuery and React together. React is unaware of changes made outside of the virtual DOM, and jQuery manipulates the standard DOM directly.

There's a write-up on how to approach this problem here.

这篇关于React JavaScript是否支持jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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