繁体   English   中英

Bootstrap 的 JavaScript 需要 jQuery - Reactjs

[英]Bootstrap's JavaScript requires jQuery - Reactjs

我必须将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';

似乎没有什么在这里工作。

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

在您的 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 要求 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 验证了它。

参考 - 问题

暂无
暂无

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

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