zer*_*ing 9 javascript reactjs material-ui
我有以下代码,没有编译:
import React from 'react';
import { AppBar, Toolbar } from 'material-ui';
import { Typography } from 'material-ui';
import { MuiThemeProvider, createMuiTheme } from 'material-ui/styles';
import {cyan, red} from 'material-ui/colors';
import { red400 } from 'material-ui/styles/colors';
const theme = createMuiTheme({
palette: {
primary: red400,
secondary: cyan,
},
});
const View = (props) => (
<MuiThemeProvider theme={theme}>
<AppBar position="static">
<Toolbar>
<Typography variant="title">
{props.title}
</Typography>
</Toolbar>
</AppBar>
</MuiThemeProvider>
);
export default View;
Run Code Online (Sandbox Code Playgroud)
它说:
Failed to compile
./src/Dashboard/AppBar/Views/View.js
Module not found: Can't resolve 'material-ui/styles/colors' in '/home/developer/Desktop/react-reason/example/src/Dashboard/AppBar/Views'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
在这里的评论中移动讨论:
确保安装next材料版本-ui:
npm install material-ui@next
此import语句不正确:
import { red400 } from 'material-ui/styles/colors'
它需要像:
import red from 'material-ui/colors/red';
在这里,red文档称之为"颜色对象".然后,您可以使用它来创建您的主题对象,如下所示:
const theme = createMuiTheme({
palette: {
primary: {
main: red[500], //OR red['A400'] for the accent range
contrastText: '#fff', // The text color to use
// You can also specify light, dark variants to use (it's autocomputed otherwise)
}
//You can also just assign the color object if the defaults work for you
secondary: red,
error: red
//tonalOffset
//contrastThreshold
},
});
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,键primary secondary和error接受颜色对象或'调色板意图',这是一个如下所示的对象:
interface PaletteIntention {
light?: string;
main: string;
dark?: string;
contrastText?: string;
};
Run Code Online (Sandbox Code Playgroud)
唯一需要的密钥是main.其余部分是根据main未提供的值自动计算的.
参考:
| 归档时间: |
|
| 查看次数: |
13187 次 |
| 最近记录: |