jquery - Owl Carousel - 类型错误 : Cannot read property 'fn' of undefined

标签 jquery reactjs create-react-app owl-carousel

我尝试在我的 react 应用程序中使用 owl.carousel 包。
我用 npm 安装了 jquery 和 owl.carousel 包。

npm install jquery owl.carousel

在 App.js 中
import React from 'react';
import $ from 'jquery';
import 'owl.carousel';


componentDidMount() {
$('.team-slides').owlCarousel({
// my options
});
}

我收到错误信息
TypeError: Cannot read property 'fn' of undefined.
/owl.carousel/dist/owl.carousel.js:1718

  1715 |  * @todo Navigation plugin `next` and `prev`
  1716 |  * @public
  1717 |  */
> 1718 | $.fn.owlCarousel = function(option) {
       | ^  1719 |  var args = Array.prototype.slice.call(arguments, 1);
  1720 | 
  1721 |    return this.each(function() {

请帮我解决这个问题。

最佳答案

您必须将这些包含在您的 index.html

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
    integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
    crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
    integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
    crossorigin="anonymous"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
    integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
    crossorigin="anonymous"></script>


  <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

关于jquery - Owl Carousel - 类型错误 : Cannot read property 'fn' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60134279/

相关文章:

javascript - 在react.js和Yii2 API中上传文件

reactjs - npm start 和 npm run build 失败并出现 npm ERR!代码生命周期

javascript - 强制数字输入有两位小数,并在 React 中始终显示两位小数

jquery - 如何强制隐藏+空的 <div> 占用空间?

javascript - 遍历 HTML 内容并将值作为全局变量返回

用于图像缩略图库的 jquery 数据表

javascript - 有没有一种方法可以根据用户的选择动态显示带有钩子(Hook)的多个文本字段? (值和 onChange)

reactjs - 在 create-react-app 构建中完全包含 Google Web 字体(不弹出)

reactjs - JEST + React 测试库 : should I render my component with a beforeAll before tests?

javascript - 如何在打开另一个 Accordion 文本之前关闭 Accordion 元素