如何将item.type的字符串转为html标签
import React, { Component,Fragment } from 'react'; import logo from './logo.png'; import './style.css'; import { Menu } from 'antd'; import { MailOutlined, AppstoreOutlined, SettingOutlined } from '@ant-design/icons'; class AppHeader extends Component{ constructor(props){ super(props); this.state={ list:[{ id:1, type:"<MailOutlined />", title:"VOA慢速英语" },{ id:2, type:"<AppstoreOutlined />", title:"VOA慢速英语" },{ id:3, type:"<SettingOutlined />", title:"VOA慢速英语" },{ id:4, type:"<MailOutlined />", title:"VOA慢速英语" },{ id:5, type:"<AppstoreOutlined />", title:"VOA慢速英语" },{ id:6, type:"<SettingOutlined />", title:"VOA慢速英语" }] }; } getMenuItems(){ return this.state.list.map(item => { return ( <Menu.Item key={item.id} className="app-header-menu"> <div dangerouslySetInnerHTML={item.type}></div> VOA慢速英语 </Menu.Item> ); }); } render(){ return ( <Fragment> <img src={logo} className="app-header-logo"/> <Menu className="app-header-menubox" mode="horizontal"> {this.getMenuItems()} </Menu> </Fragment> ); } } export default AppHeader;
29
收起
正在回答
2回答
同学你好,关于ant-design4.0版本的图标组件使用方法如下:
import React, { Component,Fragment } from 'react'; import logo from './logo.png'; import './style.css'; import { Menu } from 'antd'; import { MailOutlined, AppstoreOutlined, SettingOutlined } from '@ant-design/icons'; const { SubMenu } = Menu; class App extends React.Component { state = { current: 'mail', }; handleClick = e => { console.log('click ', e); this.setState({ current: e.key, }); }; render() { return ( <Menu onClick={this.handleClick} selectedKeys={[this.state.current]} mode="horizontal"> <Menu.Item key="mail"> <MailOutlined /> One </Menu.Item> <Menu.Item key="app"> <AppstoreOutlined /> Two </Menu.Item> </Menu> ); } } ReactDOM.render(<App />, document.getElementById('container'));
希望可以帮到你!
4.Vue与React高级框架开发
- 参与学习 人
- 提交作业 239 份
- 解答问题 10739 个
本阶段带你深入前端开发的肌理,通过ES6基础知识和前端主流高级框架的学习,助你快速构建企业级移动webAPP应用,进入职场的终极battle
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星