我不明白为什么这个导航下拉菜单不起作用。我的阅读表明它可能与添加 react-popper 依赖项有关,但我真的不明白这是如何实现的。这是 bootstrap 4 beta + create-react-app + reactstrap 5.0.0-alpha.4。遵循 reactstrap文档。
引导代码:
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
render() {
return (
<nav className="navbar navbar-expand-sm navbar-light bg-light mb-3">
<div className="container">
<a className="navbar-brand" href="#">
Navbar
</a>
<button
className="navbar-toggler"
data-toggle="collapse"
data-target="#navbarNav"
>
<span className="navbar-toggler-icon" />
</button>
<div className="collapse navbar-collapse" id="navbarNav">
<ul className="navbar-nav">
<li className="nav-item">
<a className="nav-link" href="#">
Home
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
About
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
Services
</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">
Contact
</a>
</li>
</ul>
</div>
</div>
</nav>
);
}
}
export default App;
依赖包.json:
{
"name": "basic-reactstrap-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.0.0-beta.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-popper": "^0.7.4",
"react-scripts": "1.0.17",
"reactstrap": "^5.0.0-alpha.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}