-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧐[问题 | question] 关于V5动态菜单图标的优雅解决问题 #10158
Comments
This was referenced Aug 22, 2022
Closed
你这样引入所有的图标太大了.... 还不如手写一个icons.tsx 文件 |
是有增大项目文件的问题,不过已经解决了这个警告,但是现在动态加载菜单的话二级菜单的图标不会显示,还在寻找解决办法 |
This was referenced Aug 31, 2022
This was referenced Sep 8, 2022
This was referenced Sep 19, 2022
这个是专门的,为了防止icon太多眼花缭乱 |
怎么解决的呢大佬 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🧐 问题描述 | Problem description
目前使用了动态菜单,发现动态菜单图标无法正常加载,经过查阅资料,找到以下解决问题的办法
💻 示例代码 | Sample code
import React from 'react';
import { MenuDataItem } from '@ant-design/pro-layout';
import * as allIcons from '@ant-design/icons';
// FIX从接口获取菜单时icon为string类型
const fixMenuItemIcon = (menus: MenuDataItem[], iconType = 'Outlined'): MenuDataItem[] => {
menus.forEach((item) => {
const { icon, children } = item;
if (typeof icon === 'string') {
let fixIconName = icon.slice(0, 1).toLocaleUpperCase() + icon.slice(1) + iconType;
item.icon = React.createElement(allIcons[fixIconName] || allIcons[icon]);
}
children && children.length > 0 ? (item.children = fixMenuItemIcon(children)) : null;
});
return menus;
};
export default fixMenuItemIcon;
在layout组件中直接调用
menuDataRender={() => fixMenuItemIcon(menus.menusData)}
但是使用了这个办法之后,会出现一下警告,大概意思就是说引入包的方式有问题
OS:
Node:
浏览器 | browser:
The text was updated successfully, but these errors were encountered: