React 18 -MUI-更改字体家庭
我创建了一个主题来更改MUI
的默认字体家族 但这无效。
这是我的主题组件:
import { createTheme } from "@mui/material/styles";
const theme = createTheme({
typography: {
fontFamily: ["samim", "vazir"].join(","),
},
});
export default theme;
我在我的主app.tsx
中使用主题组件来更改项目所有部分的字体
import React from "react";
import { ThemeProvider } from "@material-ui/styles";
import theme from "./theme/theme";
import Routes from "./routes/Routs";
const App = () => {
return (
<ThemeProvider theme={theme}>
<Routes />;
</ThemeProvider>
);
};
export default App;
,任何人可以帮助我吗?
I create a theme to change the default font family of MUI
But it didn't work.
this is my theme component:
import { createTheme } from "@mui/material/styles";
const theme = createTheme({
typography: {
fontFamily: ["samim", "vazir"].join(","),
},
});
export default theme;
I use the theme component in my main app.tsx
to change the font in all parts of my project
import React from "react";
import { ThemeProvider } from "@material-ui/styles";
import theme from "./theme/theme";
import Routes from "./routes/Routs";
const App = () => {
return (
<ThemeProvider theme={theme}>
<Routes />;
</ThemeProvider>
);
};
export default App;
can anyone help me, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改整个项目字体家族的最佳方法是使用MUI的 csssbaseline 。
theme.ts:
app.tsx:
The best way to change the font family of entire project is using MUI's CSSBaseline.
theme.ts:
app.tsx:
您可以尝试一下。
准备如下的主题组件。
然后,您可以在以下内容中应用于app.js。
You can try this.
Prepare theme component like below.
Then you can apply this in app.js like below.
创建的代码沙盒演示用于自定义材料UI主题,
demo link
您在哪里使用文本进行主题来进行
官方文档的链接
https://mui.com/material-ui/customization y/customization/typography/
也,您需要从 @mui/材料/样式导入theprovider
Created Code sandbox Demo for customizing Material UI Theme,
Demo Link
You would need to use Typography component where you are using text for theme part to take effect
Link from official Docs
https://mui.com/material-ui/customization/typography/
Also, you would need to import ThemeProvider from @mui/material/styles