javascript - Material-UI - 如何在 AppBar 上渲染一些东西?
问题描述
我正在使用 Material-UI 框架开发一个 React Web 应用程序。我现在已经到了想要在 AppBar 上渲染一些东西的地步,但是来自不同的文件。
我的应用程序结构如下:
Main.js - 包含 AppBar 和 react-router
react-router 作为 Main.js 的子项加载的各种视图或“页面”
这些页面呈现的各种组件。
您可以在下面看到我想要实现的目标。
如果有帮助,这里是 AppBar 的代码,请注意;我也尝试过“静态”位置。
<AppBar position="fixed">
<Toolbar>
<IconButton
edge="start"
className={classes.menuButton}
color="inherit"
aria-label="menu"
onClick={handleClick}>
<MenuIcon/>
</IconButton>
<Typography variant="h4" className={classes.title}>
<Link href="/" variant="h4" color="inherit">Site Name</Link>
</Typography>
</Toolbar>
<div>
<Menu
id="Menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}>
<MenuItem onClick={handleClose}>
// SOME MENU ITEM
</MenuItem>
</Menu>
</div>
</AppBar>
以及我试图呈现小部件的页面。现在我只是使用 Typography 组件作为占位符。我的理解是,我需要设置包含此小部件的 div 的 Z 索引以提升它,但是,我假设它仅与此视图中的其他组件相关,而不是来自 AppBar别处?
<div>
<div
style={{
height: 20,
backgroundColor: "yellow",
position: "relative",
zIndex: 10
}}>
<Typography component="h3" variant="h3">Widget Placeholder</Typography>
</div>
<Toolbar></Toolbar> // Empty toolbar is used to push all the other content down below the AppBar when it's position is set to fixed
// other content from this page
</div>
代码沙箱:https ://codesandbox.io/s/goofy-feather-cf1kd?file=/src/App.js
谢谢 :)
解决方案
推荐阅读
- python - 我需要让 python 每天重启一次我的树莓派
- security - http 视频无法在 Video.js 上的 https 网站上播放
- python - 为什么 0.2+0.1 和 3*0.1 在 python 中表现异常?
- r - 创建面板数据,填补年份之间的空白并使用 R 在随后的年份中重复最后一个值
- c - 在这个 char 指针的某些情况下发现错误?
- wordpress - 当我发送链接(我的网站)时,它会显示主题名称和模板名称,我该如何修复?
- angular - 即使一个失败并且已经有一个用于 catchError 的管道,CombineLatest 也会继续
- json - 是否可以将 json 数据写入 azure blob 存储中的文件而不将其转换为字符串?
- python - Google Drive API OAuth 2.0:ERR_CONNECTION_REFUSED
- mongodb - Mongo升级到4.2.5后启动慢