如何在 React 中自定义 Antd v5+ 中的各个菜单项?

问题描述 投票:0回答:1

我想更改一些项目的背景颜色、边框半径等,但我该怎么做?

const items1: MenuProps['items'] = ['Personal', 'Bisnis', 'Masuk'].map((key) => ({
    key,
    label: `${key}`
}));

<Menu
                theme="dark"
                mode="horizontal"
                items={items1}
                style={{ flex: 1, minWidth: 0, justifyContent: 'end', background: 'transparent', color: 'white' }}
            />

这是我的代码,在 antd 的文档中只有 key、icon、children 和 label。

reactjs antd
1个回答
0
投票

您只需将项目放入

Menu.Item
子组件中即可。

尝试使用以下代码:

{items1.map((item) => (
    <Menu.Item
      key={item.key}
      style={{
        borderRadius: '10px',
        backgroundColor: item.key === 'Personal' ? '#B039CC' : 'transparent',
      }}
    >
      {item.label}
    </Menu.Item>
  ))}
© www.soinside.com 2019 - 2024. All rights reserved.