簡體   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