Material-UI 的 Button 组件为什么样式没生效?

UX一莹 阅读 16

我刚在 React 项目里装了 @mui/material,想用它的 Button 组件,但页面上显示的就是个普通按钮,没有任何 Material 风格的样式。是不是漏了什么?

我已经按文档引入了组件,也加了 ThemeProvider,但还是不行。控制台也没报错,就是样式没加载。

import { Button } from '@mui/material';
import { createTheme, ThemeProvider } from '@mui/material/styles';

const theme = createTheme();

function App() {
  return (
    <ThemeProvider theme={theme}>
      <Button variant="contained" color="primary">
        点我
      </Button>
    </ThemeProvider>
  );
}
我来解答 赞 1 收藏
二维码
手机扫码查看
1 条解答
Prog.雯婷
漏了引入 @emotion/react@emotion/styled。装完这两个包,再在入口文件顶部加上:
import '@emotion/react';
import '@emotion/styled';

就行了。
点赞
2026-03-26 20:08