先放图,一个头部组件 index.js import React,{Component} from 'react'; import ReactDom from 'react-d
import React,{Component} from 'react';
import ReactDom from 'react-dom';
import { Layout } from 'antd';
import 'antd/dist/antd.css';
import './style.css';
import AppHeader from './components/AppHeader/';
const { Header,Footer,Content } = Layout;
class App extends Component{
render(){
return(
<Layout style={{minWidth:1200}}>
<Header className="header"><AppHeader/></Header>
<Content className="content">Content</Content>
<Footer className="footer">Footer</Footer>
</Layout>
)
}
}
ReactDom.render(<App/>,document.getElementById('root'));
.header{
background-color: #fff;
border-bottom:1px solid #999;
}
.content{
min-height:600px;
}
.footer{
text-align: center;
border-top:1px solid #999;
}
import React,{Component,Fragment} from 'react';
import logo from './logo.png';
import { Menu } from 'antd';
import {MailOutlined} from '@ant-design/icons';
import axios from 'axios';
import { Icon } from '@ant-design/compatible';
class AppHeader extends Component{
constructor(props){
super(props);
this.state={
list:[]
}
}
componentDidMount(){
axios.get("http://www.dell-lee.com/react/api/header.json")
.then(res=>{
console.log(res.data.data);
this.setState({
list:res.data.data
})
})
}
createMenuItem(){
return this.state.list.map(item=>{
(
<Menu.Item key={item.id}>
<Icon type={item.icon} />
{item.title}
</Menu.Item>
)
})
}
render(){
(
<Fragment>
<img src={logo} className="logo" />
<Menu mode="horizontal" className="menu">{this.createMenuItem()}</Menu>
</Fragment>
)
}
}
export default AppHeader;
.logo{
height:45px;
float:left;
margin-top:10px;
}
.menu{
margin-left:40px !important;45px !important;none !important;
}
import { Icon,Button } from 'antd';
const Demo = () => (
<div>
<Icon type="smile" />
<Button icon="smile" />
</div>
);
import { Button } from 'antd';
// tree-shaking supported
- import { Icon } from 'antd';
+ import { SmileOutlined } from '@ant-design/icons';
const Demo = () => (
<div>
- <Icon type="smile" />
+ <SmileOutlined />
<Button icon={<SmileOutlined />} />
</div>
);
or directly import
import SmileOutlined from '@ant-design/icons/SmileOutlined';
import { Button } from 'antd' (
<div>
<Icon type="smile" />
<Button icon="smile" />
</div>
);
当前项目文件夹下要 cnpm install --save @ant-design/compatible
总结