【发布时间】:2020-07-14 22:38:30
【问题描述】:
我正在使用 React 制作一个简单的网页,并使用 Material-ui 中的 createMuiTheme 在主题中定义了以下调色板。
palette: {
primary: {
main: "#333333"
},
secondary: {
main: "#727171"
},
background: {
paper: "#f8f3f0",
default: "#f8f3f0"
},
accent: {
main: "#80d6d1"
}
}
然后,当我想为我使用的某些文本使用我的强调色时:
const useStyles = makeStyles(theme => ({
content: {
backgroundColor: theme.palette.background.default,
minHeight: "90vh"
color: theme.palette.background.main
}
}));
我收到以下错误:
TypeError: Cannot read property 'main' of undefined
71 | minHeight: "90vh"
> 72 | color: theme.palette.accent.main
73 | }
74 | }));
你有什么想法吗?
【问题讨论】:
-
木槌对象中没有背景属性,你只有主次元和重音
-
其实是有的,我这里略过,以免太长。我会添加它以免混淆(我现在没有必要)
-
使用theme.palette.accent.main.
-
尝试添加
console.log(theme.palette)并确保accent属性存在。 -
还是 theme.palette.background.main 不存在,没有 main !
标签: css node.js reactjs material-ui