Skip to content
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

🐛 [BUG]动态渲染Menu菜单总是默认选中最后一项且无法选择其他项 #10874

Closed
ZhuYuRan001 opened this issue Aug 4, 2023 · 1 comment

Comments

@ZhuYuRan001
Copy link

ZhuYuRan001 commented Aug 4, 2023

🐛 bug 描述

在app.tsx中layout对象里使用request获取到数据并渲染的菜单总是会默认选中菜单的最后一项,并触发两次onSelect事件。并且后续的onClick和onSelect事件都失效了。也无法再选中其他项菜单。

📷 复现步骤 | Recurrence steps

🏞 期望结果 | Expected results

💻 复现代码 | Recurrence code

//从服务器获取菜单数据
menu: {
// 每当 initialState?.currentUser?.userid 发生修改时重新执行 request
params: {
// userId: initialState
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
request: async (params: void, defaultMenuData: any) => {
const menus = await getMenuList().then((res: any) => {
return res.data.map((item: any) => {
subMenuArr.push(item.id)
return {
path: '/',
name: item.meta.title,
icon: React.createElement(allIcons['SettingOutlined']),
key: item.name + item.meta.title,
routes: item.children.map((element: any) => {
return {
// path: '/?path=' + element.fullUrl,
// path: 'https://procomponents.ant.design/components/layout',
path: '/',
name: element.meta.title,
key: element.name + element.meta.title,
};
}),
};
});
});
// initialState.currentUser 中包含了所有用户信息
setInitialState({ ...initialState, rootSubmenuKeys: subMenuArr })
return menus;
},
onClick: ({ item }: { item: any }) => {
console.log(item, 'item,选中菜单');
},
},

© 版本信息

  • Ant Design Pro 版本: 6.0.0
  • umi 版本:4
  • 浏览器环境:edge
  • 开发环境 [e.g. windows 11]

🚑 其他信息

1691131558272
1691131575108(1)

@github-actions
Copy link

github-actions bot commented Aug 4, 2023

当前 Issue 未检测到标题,请规范填写,谢谢!

The title of the current issue is not detected, please fill in according to the specifications, thank you!

@github-actions github-actions bot closed this as completed Aug 4, 2023
@ZhuYuRan001 ZhuYuRan001 changed the title 🐛 [BUG] 🐛 [BUG]动态渲染Menu菜单总是默认选中最后一项且无法选择其他项 Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant