简体   繁体   English

Bootstrap 的 JavaScript 需要 jQuery - Reactjs

[英]Bootstrap's JavaScript requires jQuery - Reactjs

I have to use bootstrap with reactjs and when i try to import Bootstrap.js it gives me error我必须将bootstrapreactjs一起使用,当我尝试导入 Bootstrap.js 时,它给了我错误

Bootstrap's JavaScript requires jQuery Bootstrap 的 JavaScript 需要 jQuery

Here is my import statements (I tried following)这是我的导入语句(我尝试以下)

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

Nothing is seems to work here.似乎没有什么在这里工作。

You can use React Bootstrap as well as an alternative.您可以使用React Bootstrap以及替代方法。 It has all elements of the Bootstrap plus it blends well with ReactJS elements.它具有 Bootstrap 的所有元素,并且与 ReactJS 元素很好地融合在一起。

in your HTML file:在您的 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>

Bootstrap requires jquery to be available on the global object. Bootstrap 要求 jquery 在全局对象上可用。 Try the below -尝试以下 -

import 'bootstrap/dist/css/bootstrap.min.css';

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

I have verified it for bootstrap@3.3.7 and jquery@2.2.4.我已经为 bootstrap@3.3.7 和 jquery@2.2.4 验证了它。

Ref - issue参考 - 问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM