添加具有 material-table 的组件更改 Material-UI AppBar 样式
Adding component with material-table changes Material-UI AppBar style
我的应用正在使用 Material-UI 和 material-table。在 "index.js" 文件中应用全局主题,使用 "ThemeProvider" 作为子项,然后有子项:
<Fragment>
<CssBaseline />
<MenuAppBar />
<main className={classes.main}>
<Route path="/" exact component={Home} />
<Route path="/login" component={Login}></Route>
</main>
</Fragment>
该组件然后具有具有material-table的组件。当我添加 table 组件并查看该页面时,AppBar 会丢失一些样式,例如Pofile 和注销下拉按钮的背景颜色和对齐方式 (https://material-ui.com/components/app-bar/#app-bar-with-menu)。我很困惑为什么会这样。
深入 CSS,在更改 AppBar 样式的页面上,我看到 .MuiPaper-root
在 .MuiAppBar-colorPrimary
之前导入,因此覆盖了样式,但仍然不确定为什么添加带有 "material-table" 的组件会导致这种情况发生。
我的应用依赖项是:
"dependencies": {
"@material-ui/core": "^4.2.1",
"@material-ui/icons": "^4.2.1",
"axios": "^0.19.0",
"jwt-decode": "^2.2.0",
"material-table": "^1.40.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"react-svg": "^10.0.11"
},
我还看到 "material-table" 列出了 "material-ui/core" 的两个不同版本,但不确定如何解决。
"material-table": {
"version": "1.40.1",
"resolved": "https://registry.npmjs.org/material-table/-/material-table-1.40.1.tgz",
"integrity": "sha512-rZuGhNpXFzROlqJUVLH+E5yzt9MxaYVZfDNuHWtM9EWlbUGQJWuGQNcsSmdr0XeTCZkQvVnZYbEkRcUu+71rfQ==",
"requires": {
"@date-io/date-fns": "^1.1.0",
"@material-ui/core": "^4.0.1",
"@material-ui/pickers": "^3.0.0",
"classnames": "^2.2.6",
"date-fns": "^2.0.0-alpha.27",
"debounce": "^1.2.0",
"filefy": "0.1.9",
"prop-types": "^15.6.2",
"react-beautiful-dnd": "11.0.3",
"react-double-scrollbar": "0.0.15"
},
"dependencies": {
"@material-ui/core": {
"version": "4.2.1",
...
通过查找其他一些帖子 1 and 2,我试图将 material-ui/core 和 material-ui/icons 的版本降级到 4.0.1 版本(与 material- 使用的相同) table) 并且有效。
完整详情:
npm uninstall @material-ui/core
npm uninstall @material-ui/icons
npm install @material-ui/core@4.0.1
npm install @material-ui/icons@4.0.1
我的应用正在使用 Material-UI 和 material-table。在 "index.js" 文件中应用全局主题,使用 "ThemeProvider" 作为子项,然后有子项:
<Fragment>
<CssBaseline />
<MenuAppBar />
<main className={classes.main}>
<Route path="/" exact component={Home} />
<Route path="/login" component={Login}></Route>
</main>
</Fragment>
该组件然后具有具有material-table的组件。当我添加 table 组件并查看该页面时,AppBar 会丢失一些样式,例如Pofile 和注销下拉按钮的背景颜色和对齐方式 (https://material-ui.com/components/app-bar/#app-bar-with-menu)。我很困惑为什么会这样。
深入 CSS,在更改 AppBar 样式的页面上,我看到 .MuiPaper-root
在 .MuiAppBar-colorPrimary
之前导入,因此覆盖了样式,但仍然不确定为什么添加带有 "material-table" 的组件会导致这种情况发生。
我的应用依赖项是:
"dependencies": {
"@material-ui/core": "^4.2.1",
"@material-ui/icons": "^4.2.1",
"axios": "^0.19.0",
"jwt-decode": "^2.2.0",
"material-table": "^1.40.1",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"react-svg": "^10.0.11"
},
我还看到 "material-table" 列出了 "material-ui/core" 的两个不同版本,但不确定如何解决。
"material-table": {
"version": "1.40.1",
"resolved": "https://registry.npmjs.org/material-table/-/material-table-1.40.1.tgz",
"integrity": "sha512-rZuGhNpXFzROlqJUVLH+E5yzt9MxaYVZfDNuHWtM9EWlbUGQJWuGQNcsSmdr0XeTCZkQvVnZYbEkRcUu+71rfQ==",
"requires": {
"@date-io/date-fns": "^1.1.0",
"@material-ui/core": "^4.0.1",
"@material-ui/pickers": "^3.0.0",
"classnames": "^2.2.6",
"date-fns": "^2.0.0-alpha.27",
"debounce": "^1.2.0",
"filefy": "0.1.9",
"prop-types": "^15.6.2",
"react-beautiful-dnd": "11.0.3",
"react-double-scrollbar": "0.0.15"
},
"dependencies": {
"@material-ui/core": {
"version": "4.2.1",
...
通过查找其他一些帖子 1 and 2,我试图将 material-ui/core 和 material-ui/icons 的版本降级到 4.0.1 版本(与 material- 使用的相同) table) 并且有效。
完整详情:
npm uninstall @material-ui/core
npm uninstall @material-ui/icons
npm install @material-ui/core@4.0.1
npm install @material-ui/icons@4.0.1