【问题标题】:How to import jquery in App.js in React JS如何在 React JS 中的 App.js 中导入 jquery
【发布时间】:2019-08-17 06:30:04
【问题描述】:

我想将引导布局集成到 ReactJS 中。在这里,我遇到了一个问题,因为我错过了引导程序中的一个 jquery 文件,因此我的代码无法正常工作。 我很困惑如何在 App.js 中集成 Jquery

import './App.css';
import './css/bootstrap.min.css';
import './css/style.css'; 
import './css/slick.css';    
import './js/slick.min.js';   //Jquery   

错误显示为:

Line 17:     'define' is not defined no-undef
Line 17:     'define' is not defined no-undef
Line 17:    'jQuery' is not defined no-undef
Line 17:     Expected an assignment or function call and instead saw an 
             expression  no-unused-expressions
Line 17:     Expected an assignment or function call and instead saw an 
             expression  no-unused-expressions 

如何在 App.js 中添加 slick.min.js

【问题讨论】:

  • 有 npm 你可以用 npm 来做 slick
  • 您是否链接到 jQuery CDN?
  • 不,我没有使用 jquery CDN。我从本地目录链接它

标签: reactjs


【解决方案1】:

引用自:https://stackoverflow.com/a/33351325/11932228

首先尝试将 jquery 包含到您的项目中

只需使用 npm 安装 jquery 包: npm i jquery --save

或者如果你使用 yarnyarn add jquery

或者如果你使用 bowerbower i jquery --save

在您的 App.js 中:import $ from 'jquery';

如果它仍然不起作用,您可能需要检查布局的要求,它可能与 react 不兼容。

【讨论】:

  • 表明 : $ 被声明但它的值从未被使用过
  • 你是否删除了 slick.min.js 的导入并仅导入 $,并在导入 './App.css' 之前在顶部执行此操作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-07
  • 2016-09-23
  • 1970-01-01
相关资源
最近更新 更多