How to install popper.js with Bootstrap 4?

后端 未结 11 846
眼角桃花
眼角桃花 2020-12-07 17:17

From what I\'ve read so far, popper.js is a big pain with Bootstrap 4. I can\'t get it to work. I keep getting this error:

Error: Bootstrap dropdown r

相关标签:
11条回答
  • 2020-12-07 18:04

    Two different ways I got this working.

    Option 1: Add these 3 <script> tags to your .html file, just before the closing </body> tag:

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

    Option 2 (Option 2 works with Angular, not sure about other frameworks)

    Step 1: Install the 3 libraries using NPM:

    npm install bootstrap --save

    npm install popper.js --save

    npm install jquery --save

    Step 2: Update the script: array(s) in your angular.json file like this:

    "scripts": ["node_modules/jquery/dist/jquery.min.js", "node_modules/popper.js/dist/umd/popper.min.js", "node_modules/bootstrap/dist/js/bootstrap.min.js"]
    

    (thanks to @rakeshk-khanapure above in the comments)

    0 讨论(0)
  • 2020-12-07 18:08

    npm install bootstrap jquery --save

    You don't have to install popper.js with npm as it comes with npm Bootstrap in bootstrap.bundle.js.

    Bundled JS files (bootstrap.bundle.js and minified bootstrap.bundle.min.js) include Popper, but not jQuery.

    Source to Verify: Link

    Now you only have to do this in your HTML file:

    <script src="node_modules/jquery/dist/jquery.slim.min.js"></script>
    <script src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
    
    0 讨论(0)
  • 2020-12-07 18:10

    Instead of remotely putting popper js from CDN you can directly install it in your angular project.

    Try this.

    npm install popper.js --save 
    

    This query installs an updated version of popper.js Don't mention any version there, it will work for you.

    0 讨论(0)
  • 2020-12-07 18:11

    It's simple you can Visit this, And save the file as popper.min.js

    then import it.

    import React from 'react';
    import ReactDOM from 'react-dom';
    import App from './App';
    import 'bootstrap/dist/css/bootstrap.css';
    import './index.css';
    import 'bootstrap/dist/js/popper.min.js';
    global.jQuery = require('jquery');
    require('bootstrap');
    
    0 讨论(0)
  • 2020-12-07 18:13

    Try doing this:

    npm install bootstrap jquery popper.js --save
    

    See this page for more information: how-to-include-bootstrap-in-your-project-with-webpack

    0 讨论(0)
提交回复
热议问题