【问题标题】:Adding own objects in createMuiTheme [duplicate]在createMuiTheme中添加自己的对象[重复]
【发布时间】:2021-02-04 12:40:54
【问题描述】:

是否可以将自定义对象添加到“createMuiTheme”? 假设我在 AppBar 中有一个购物车图标,我可以如何注入它以便它在“createMuiTheme”中可用?

类似这样的:

const theme = createMuiTheme({
    custom: {
        CartIcon: {
            color: "#333"
        }
    }
});

【问题讨论】:

    标签: material-ui themes


    【解决方案1】:

    是的。可以在 MUI 主题对象中添加自定义对象。
    您已经在对象中添加了自定义CartIcon 颜色,现在您可以通过以下方式访问makeStyles 中的该对象:-

    const useStyles = makeStyles((theme) => ({
        cartClass:{
          color:theme.custom.CartIcon.color;
        }
    }));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多