我刚刚开始学习React.js和material-ui。我正在使用this在屏幕上显示一个图标。但是,图标不会显示在屏幕上,并且屏幕显示为空白。
这是我的代码:
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import {IconButtonExampleSimple} from './IconButtonExampleSimple.js';
class App extends React.Component{
render()
{
return(
<MuiThemeProvider>
<IconButtonExampleSimple />
</MuiThemeProvider>
);
}
}
ReactDOM.render(
<App/>,
document.getElementById('root')
);
IconButtonExampleSimple.js
import React from 'react';
import IconButton from 'material-ui/IconButton';
export class IconButtonExampleSimple extends React.Component{
render ()
{
return (<div>
<IconButton iconClassName="muidocs-icon-custom-github" />
<IconButton iconClassName="muidocs-icon-custom-github"
disabled={true} />
</div>
);
}
}
将此行添加到index.html
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
您正在包含图标按钮的Material-UI部分,但这些部分指的是Google的Material-Icons,因此您必须将其链接到索引文件中。