1 回答
TA贡献2039条经验 获得超7个赞
我创建了一个简单的popUpMenu使用状态。您可以检查一下以了解一些想法。
function App() {
const [popUpMenu, setPopUpMenu] = React.useState(false);
return (
<div className="App">
<button onClick={() => setPopUpMenu(!popUpMenu)}>
Menu with Dropdown
</button>
{popUpMenu && PopUpMenu()}
</div>
);
}
function PopUpMenu() {
return (
<ul className="drop-down">
<li>Menu-item-1</li>
<li>Menu-item-2</li>
<li>Menu-item-3</li>
</ul>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
.drop-down {
list-style: none;
}
.drop-down li {
padding: 10px 0px;
border-bottom: 1px solid #cccccc;
width: 100px;
text-align: center;
background: #fbf6f6;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.7.0-alpha.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.7.0-alpha.2/umd/react-dom.production.min.js"></script>
<div id="root"></div>
- 1 回答
- 0 关注
- 100 浏览
添加回答
举报