Bootstrap Dropdown is not working in React

徘徊边缘 提交于 2021-01-29 04:12:02

问题


I include a dropdown button to React from bootstrap Dropdowns, But it is not working and shows as a normal button. Can you give me a solution for this?

<div className="dropdown">
    <button className="btn btn-secondary 
                 dropdown-toggle" 
                 type="button" 
                 id="dropdownMenuButton"
                 data-toggle="dropdown"
                 aria-haspopup="true" 
                 aria-expanded="false">
                 Dropdown button
    </button>
            <div className="dropdown-menu" aria-labelledby="dropdownMenuButton">
                <a className="dropdown-item" href="#">Action</a>
                <a className="dropdown-item" href="#">Another action</a>
                <a className="dropdown-item" href="#">Something else here</a>
            </div>
</div>

The output is a normal button like this.


回答1:


Dropdowns are not working without popper.js and jquery.js.

So please install popper.js and jquery.js in your system using npm install popper.js jquery --save and don't forget to include it.

With CDN

https://stackblitz.com/edit/create-react-class-m3qfxu?file=index.html

With NPM

https://stackblitz.com/edit/create-react-class-xvsthx?file=index.js



来源:https://stackoverflow.com/questions/61305436/bootstrap-dropdown-is-not-working-in-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!