zoukankan      html  css  js  c++  java
  • React 16.3, Antd 4.2, 侧边栏的 Icon 由后端返回,Icon显示问题

    import React, { Component } from 'react';
    import { withRouter, RouteComponentProps } from 'react-router-dom';
    import { Layout, Menu } from 'antd';
    // 模拟后端返回路由 import Route, { IFMenu } from '../../router/config'; import { Link } from 'react-router-dom'; import * as Icon from '@ant-design/icons'; const { SubMenu } = Menu; const { Sider } = Layout; type SiderCustomProps = RouteComponentProps<any> & { collapsed?: boolean } type SiderCustomState = { Logo: string, Icons: any } class SiderCustom extends Component<SiderCustomProps, SiderCustomState> { constructor(props: any) { super(props) this.state = { Icons: Icon } } /* 需要注意的点 ·1.Icons,因需要后端配置图标,但and-design4.0以上版本将icon做成了引用加载,可将Icon传入state进行赋值 */ renderMenuItem = (item: IFMenu) => { let icons: any = this.state.Icons[item.icon]; return ( <Menu.Item key={item.path}> <Link to={item.path + (item.query || '')}> {React.createElement(icons, { className: 'icon', })} <span className="nav-text">{item.title}</span> </Link> </Menu.Item> ) } /* 父级 */ renderSubMenu = (item: IFMenu) => ( <SubMenu key={item.path} title={item.title}> { item.child!.map((val) => ( val.child ? this.renderSubMenu(val) : this.renderMenuItem(val) )) } </SubMenu> ) render() { return ( <Sider trigger={null} collapsible collapsed={this.props.collapsed} width="256"> <div className="menu-logo"> <Link to="/JFCC" className="a-logo"> <img src={this.state.Logo} alt="Logo" className="Logo"></img> </Link> </div> <Menu theme="dark" mode="inline" > {Route.menus.map((val: IFMenu) => { return val.child ? this.renderSubMenu(val) : this.renderMenuItem(val) })} </Menu> </Sider> ); } } export default withRouter(SiderCustom);

      

  • 相关阅读:
    [非技术]简单预测中美关系未来的走向
    权限系统模型和常用权限框架
    [Tomcat]了解Tomcat,从它的结构开始
    [Mybatis]用AOP和mybatis来实现一下mysql读写分离
    [MQ]说一说MQ消息积压
    [MQ]再谈延时队列
    [Web] 浅谈Cookie,Session,Token
    k8s搭建
    微信公众平台开发(2)扫描二维码添加公众账号
    微信公众平台开发模式
  • 原文地址:https://www.cnblogs.com/gqx-html/p/12912162.html
Copyright © 2011-2022 走看看