Bootstrap Dropdown在React中不起作用 [英] Bootstrap Dropdown is not working in React
问题描述
我包含了一个从Bootstrap Dropdowns下拉到React的下拉按钮,但是它不起作用,显示为普通按钮.你能给我一个解决方案吗?
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.
推荐答案
没有 popper.js
和 jquery.js
,下拉菜单将无法正常工作.
Dropdowns are not working without popper.js
and jquery.js
.
因此,请使用 npm install popper.js jquery --save
在系统中安装 popper.js
和 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.
使用CDN
https://stackblitz.com/edit/create-react-class-m3qfxu?file = index.html
使用NPM
https://stackblitz.com/edit/create-react-class-xvsthx?file = index.js
这篇关于Bootstrap Dropdown在React中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!