【问题标题】:Bootstrap's JavaScript requires jQuery - ReactjsBootstrap 的 JavaScript 需要 jQuery - Reactjs
【发布时间】:2017-09-26 06:10:58
【问题描述】:

我必须将 bootstrapreactjs 一起使用,当我尝试导入 Bootstrap.js 时出现错误

Bootstrap 的 JavaScript 需要 jQuery

这是我的导入语句(我试过以下)

import $ from 'jquery';
import jQuery from 'jquery'; //I installed jquery using npm
import '@shopify/polaris/jquery'; //I put jquery.js file 
import '@shopify/polaris/bootstrap';

这里似乎没有任何效果。

【问题讨论】:

  • 我认为您需要将 jquery 添加到您的 html 文件中
  • 添加到 html 文件文件,暂时消除错误。谢谢:)
  • 很高兴我能帮上忙 :)

标签: javascript jquery twitter-bootstrap reactjs


【解决方案1】:

在您的 HTML 文件中:

<html>
      <head>

           ..................
           ..................
           ..................
      </head>

      <body>
           ..................
           <script src="jquery.js"></script> // <<<<<< you missing import jquery here
           <script src="bootstrap.js"></script> // <<<<<<< you have this one
           ..................
      </body>
</html>

【讨论】:

    【解决方案2】:

    您可以使用React Bootstrap 以及替代方法。它具有 Bootstrap 的所有元素,并且可以与 ReactJS 元素很好地融合。

    【讨论】:

      【解决方案3】:

      Bootstrap 要求 jquery 在全局对象上可用。试试下面的 -

      import 'bootstrap/dist/css/bootstrap.min.css';
      
      const $ = require('jquery');
      window.$ = $;
      window.jQuery = $;
      require('bootstrap/dist/js/bootstrap.min');
      

      我已经为 bootstrap@3.3.7 和 jquery@2.2.4 验证了它。

      参考 - issue

      【讨论】:

        猜你喜欢
        • 2017-06-06
        • 2015-11-16
        • 2017-04-25
        • 2016-08-16
        • 2018-04-06
        • 2018-07-13
        • 2017-05-10
        • 1970-01-01
        • 2023-03-11
        相关资源
        最近更新 更多