Skip to content

Menu 组件,适用于平台导航等场景,分为垂直菜单,水平菜单,内嵌菜单等类型。

垂直菜单

在使用菜单导航,最常见的莫过于位于侧边的垂直菜单,其对应的type属性值为"vertical"

你可以通过items配置按需组合MenuItem, SubMenu, MenuItemGroup等组件,具体效果如下:

  • Menu Item 1
  • Menu Item 2 我的名字很长 我的名字很长 我的名字很长
  • Sub Menu 1
  • Item Group
  • Item 1 in Group
  • Item 2 in Group
展开查看代码
vue
<template>
    <div>
        <j-menu v-model:selectedKeys="selectedKeys" v-model:openKeys="openKeys" :items="items" :theme="theme" style="width: 256px"></j-menu>
    </div>
</template>

<script lang="jsx" setup>
import { ref } from 'vue'
import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'

const theme = ref('light')

const openKeys = ref([])

const selectedKeys = ref([])

const items = ref([
    {
        itemKey: '1',
        title: 'Menu Item 1',
        icon: <AccountBookOutlined />,
    },
    {
        itemKey: '2',
        title: 'Menu Item 2 我的名字很长 我的名字很长 我的名字很长',
        icon: <CalendarOutlined />,
    },
    {
        itemKey: '3',
        title: 'Sub Menu 1',
        icon: <ApartmentOutlined />,
        items: [
            {
                itemKey: '3-1',
                title: '3-1',
                icon: <AppstoreOutlined />,
            },
            {
                itemKey: '3-2',
                title: '3-2',
                icon: <CalendarOutlined />,
                items: [
                    {
                        itemKey: '3-2-1',
                        title: '3-2-1',
                        icon: <AppstoreOutlined />,
                        items: [
                            {
                                itemKey: '3-2-1-1',
                                title: '3-2-1-1',
                                icon: <AppstoreOutlined />,
                            },
                            {
                                itemKey: '3-2-1-2',
                                title: '3-2-1-2',
                                icon: <ApartmentOutlined />,
                            },
                            {
                                type: 'group',
                                itemKey: '3-2-1-3',
                                title: 'Group In SubMenu 3-2-1',
                                items: [
                                    {
                                        itemKey: '3-2-1-3-1',
                                        title: '3-2-1-3-1',
                                        icon: <AppstoreOutlined />,
                                    },
                                    {
                                        itemKey: '3-2-1-3-2',
                                        title: '3-2-1-3-2',
                                        icon: <AccountBookOutlined />,
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        itemKey: '3-2-2',
                        title: '3-2-2',
                        icon: <ApartmentOutlined />,
                    },
                ],
            },
            {
                type: 'group',
                itemKey: '3-3',
                title: 'Group 1 In SubMenu',
                items: [
                    {
                        itemKey: '3-3-1',
                        title: '3-3-1',
                        icon: <CalendarOutlined />,
                    },
                    {
                        itemKey: '3-3-2',
                        title: '3-3-2',
                        icon: <AccountBookOutlined />,
                    },
                ],
            },
        ],
    },
    {
        type: 'group',
        itemKey: '4',
        title: 'Item Group',
        items: [
            {
                itemKey: '4-1',
                title: 'Item 1 in Group',
                icon: <AppstoreOutlined />,
            },
            {
                itemKey: '4-2',
                title: 'Item 2 in Group',
                icon: <CalendarOutlined />,
            },
        ],
    },
])
</script>
<template>
    <div>
        <j-menu v-model:selectedKeys="selectedKeys" v-model:openKeys="openKeys" :items="items" :theme="theme" style="width: 256px"></j-menu>
    </div>
</template>

<script lang="jsx" setup>
import { ref } from 'vue'
import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'

const theme = ref('light')

const openKeys = ref([])

const selectedKeys = ref([])

const items = ref([
    {
        itemKey: '1',
        title: 'Menu Item 1',
        icon: <AccountBookOutlined />,
    },
    {
        itemKey: '2',
        title: 'Menu Item 2 我的名字很长 我的名字很长 我的名字很长',
        icon: <CalendarOutlined />,
    },
    {
        itemKey: '3',
        title: 'Sub Menu 1',
        icon: <ApartmentOutlined />,
        items: [
            {
                itemKey: '3-1',
                title: '3-1',
                icon: <AppstoreOutlined />,
            },
            {
                itemKey: '3-2',
                title: '3-2',
                icon: <CalendarOutlined />,
                items: [
                    {
                        itemKey: '3-2-1',
                        title: '3-2-1',
                        icon: <AppstoreOutlined />,
                        items: [
                            {
                                itemKey: '3-2-1-1',
                                title: '3-2-1-1',
                                icon: <AppstoreOutlined />,
                            },
                            {
                                itemKey: '3-2-1-2',
                                title: '3-2-1-2',
                                icon: <ApartmentOutlined />,
                            },
                            {
                                type: 'group',
                                itemKey: '3-2-1-3',
                                title: 'Group In SubMenu 3-2-1',
                                items: [
                                    {
                                        itemKey: '3-2-1-3-1',
                                        title: '3-2-1-3-1',
                                        icon: <AppstoreOutlined />,
                                    },
                                    {
                                        itemKey: '3-2-1-3-2',
                                        title: '3-2-1-3-2',
                                        icon: <AccountBookOutlined />,
                                    },
                                ],
                            },
                        ],
                    },
                    {
                        itemKey: '3-2-2',
                        title: '3-2-2',
                        icon: <ApartmentOutlined />,
                    },
                ],
            },
            {
                type: 'group',
                itemKey: '3-3',
                title: 'Group 1 In SubMenu',
                items: [
                    {
                        itemKey: '3-3-1',
                        title: '3-3-1',
                        icon: <CalendarOutlined />,
                    },
                    {
                        itemKey: '3-3-2',
                        title: '3-3-2',
                        icon: <AccountBookOutlined />,
                    },
                ],
            },
        ],
    },
    {
        type: 'group',
        itemKey: '4',
        title: 'Item Group',
        items: [
            {
                itemKey: '4-1',
                title: 'Item 1 in Group',
                icon: <AppstoreOutlined />,
            },
            {
                itemKey: '4-2',
                title: 'Item 2 in Group',
                icon: <CalendarOutlined />,
            },
        ],
    },
])
</script>

内嵌菜单

如果你不希望子菜单是弹出的形式,可以考虑使用内嵌菜单,仅仅需要设置type属性为inline即可。

  • Menu Item 1
  • Menu Item 2
  • Sub Menu 1
  • 3-2-2
  • Group 1 In SubMenu
  • 3-3-1
  • 3-3-2
  • Item Group
  • Item 1 in Group
  • Item 2 in Group
  • 展开查看代码
    vue
    <template>
        <div>
            <j-menu
                type="inline"
                v-model:selectedKeys="selectedKeys"
                v-model:openKeys="openKeys"
                :items="items"
                :theme="theme"
                style="width: 256px"
            ></j-menu>
        </div>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const theme = ref('light')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <ApartmentOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group In SubMenu 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: '3-2-1-3-1',
                                            icon: <AppstoreOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: '3-2-1-3-2',
                                            icon: <AccountBookOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <ApartmentOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 1 In SubMenu',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: '3-3-1',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: '3-3-2',
                            icon: <AccountBookOutlined />,
                        },
                    ],
                },
            ],
        },
        {
            type: 'group',
            itemKey: '4',
            title: 'Item Group',
            items: [
                {
                    itemKey: '4-1',
                    title: 'Item 1 in Group',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '4-2',
                    title: 'Item 2 in Group',
                    icon: <CalendarOutlined />,
                },
            ],
        },
    ])
    </script>
    <template>
        <div>
            <j-menu
                type="inline"
                v-model:selectedKeys="selectedKeys"
                v-model:openKeys="openKeys"
                :items="items"
                :theme="theme"
                style="width: 256px"
            ></j-menu>
        </div>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const theme = ref('light')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <ApartmentOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group In SubMenu 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: '3-2-1-3-1',
                                            icon: <AppstoreOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: '3-2-1-3-2',
                                            icon: <AccountBookOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <ApartmentOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 1 In SubMenu',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: '3-3-1',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: '3-3-2',
                            icon: <AccountBookOutlined />,
                        },
                    ],
                },
            ],
        },
        {
            type: 'group',
            itemKey: '4',
            title: 'Item Group',
            items: [
                {
                    itemKey: '4-1',
                    title: 'Item 1 in Group',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '4-2',
                    title: 'Item 2 in Group',
                    icon: <CalendarOutlined />,
                },
            ],
        },
    ])
    </script>

    可收起的内嵌菜单

    使用inlineCollapsed属性可以实现菜单的收起效果。

    收起
    • Menu Item 1
    • Menu Item 2
    • Sub Menu 1
  • 3-2-2
  • Group 1 In SubMenu
  • 3-3-1
  • 3-3-2
  • Item Group
  • Item 1 in Group
  • Item 2 in Group
  • 展开查看代码
    vue
    <template>
        <div style="width: 256px">
            <j-space align="center">
                收起
                <j-switch v-model:checked="inlineCollapsed" />
            </j-space>
    
            <j-menu
                type="inline"
                v-model:selectedKeys="selectedKeys"
                v-model:openKeys="openKeys"
                :inlineCollapsed="inlineCollapsed"
                :items="items"
                :theme="theme"
                style="margin-top: 20px"
            ></j-menu>
        </div>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const inlineCollapsed = ref(true)
    
    const theme = ref('light')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <ApartmentOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group In SubMenu 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: '3-2-1-3-1',
                                            icon: <AppstoreOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: '3-2-1-3-2',
                                            icon: <AccountBookOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <ApartmentOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 1 In SubMenu',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: '3-3-1',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: '3-3-2',
                            icon: <AccountBookOutlined />,
                        },
                    ],
                },
            ],
        },
        {
            type: 'group',
            itemKey: '4',
            title: 'Item Group',
            items: [
                {
                    itemKey: '4-1',
                    title: 'Item 1 in Group',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '4-2',
                    title: 'Item 2 in Group',
                    icon: <CalendarOutlined />,
                },
            ],
        },
    ])
    </script>
    <template>
        <div style="width: 256px">
            <j-space align="center">
                收起
                <j-switch v-model:checked="inlineCollapsed" />
            </j-space>
    
            <j-menu
                type="inline"
                v-model:selectedKeys="selectedKeys"
                v-model:openKeys="openKeys"
                :inlineCollapsed="inlineCollapsed"
                :items="items"
                :theme="theme"
                style="margin-top: 20px"
            ></j-menu>
        </div>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const inlineCollapsed = ref(true)
    
    const theme = ref('light')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <ApartmentOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group In SubMenu 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: '3-2-1-3-1',
                                            icon: <AppstoreOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: '3-2-1-3-2',
                                            icon: <AccountBookOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <ApartmentOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 1 In SubMenu',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: '3-3-1',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: '3-3-2',
                            icon: <AccountBookOutlined />,
                        },
                    ],
                },
            ],
        },
        {
            type: 'group',
            itemKey: '4',
            title: 'Item Group',
            items: [
                {
                    itemKey: '4-1',
                    title: 'Item 1 in Group',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '4-2',
                    title: 'Item 2 in Group',
                    icon: <CalendarOutlined />,
                },
            ],
        },
    ])
    </script>

    水平菜单

    水平菜单,适用于网站顶部导航,设置type属性为horizontal即可。

    展开查看代码
    vue
    <template>
        <j-menu
            v-model:selectedKeys="selectedKeys"
            v-model:openKeys="openKeys"
            :items="items"
            :theme="theme"
            type="horizontal"
            style="margin: 0 0 40px"
        ></j-menu>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const theme = ref('light')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <CalendarOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group 1 in 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: 'Item 1 in Group 1',
                                            icon: <CalendarOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: 'Item 2 in Group 1',
                                            icon: <CalendarOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <CalendarOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 3-3',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: 'Item 1 in Group 3-3',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: 'Item 2 in Group 3-3',
                            icon: <CalendarOutlined />,
                        },
                    ],
                },
            ],
        },
    ])
    </script>
    <template>
        <j-menu
            v-model:selectedKeys="selectedKeys"
            v-model:openKeys="openKeys"
            :items="items"
            :theme="theme"
            type="horizontal"
            style="margin: 0 0 40px"
        ></j-menu>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const theme = ref('light')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <CalendarOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group 1 in 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: 'Item 1 in Group 1',
                                            icon: <CalendarOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: 'Item 2 in Group 1',
                                            icon: <CalendarOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <CalendarOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 3-3',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: 'Item 1 in Group 3-3',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: 'Item 2 in Group 3-3',
                            icon: <CalendarOutlined />,
                        },
                    ],
                },
            ],
        },
    ])
    </script>

    切换主题

    通过theme属性为切换主题,支持"light""dark"两种类型。

    收起
    主题
    • Menu Item 1
    • Menu Item 2
    • Sub Menu 1
  • 3-2-2
  • Group 1 In SubMenu
  • 3-3-1
  • 3-3-2
  • Item Group
  • Item 1 in Group
  • Item 2 in Group
  • 展开查看代码
    vue
    <template>
        <div style="width: 256px">
            <j-space align="center">
                <j-space align="center">
                    收起
                    <j-switch v-model:checked="inlineCollapsed" />
                </j-space>
                <j-space align="center">
                    主题
                    <j-switch
                        checked-children="D"
                        unchecked-children="L"
                        checked-value="dark"
                        unchecked-value="light"
                        v-model:checked="theme"
                    />
                </j-space>
            </j-space>
            <j-menu
                type="inline"
                v-model:selectedKeys="selectedKeys"
                v-model:openKeys="openKeys"
                :inlineCollapsed="inlineCollapsed"
                :items="items"
                :theme="theme"
                style="margin-top: 20px"
            ></j-menu>
        </div>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const inlineCollapsed = ref(true)
    
    const theme = ref('dark')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <ApartmentOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group In SubMenu 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: '3-2-1-3-1',
                                            icon: <AppstoreOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: '3-2-1-3-2',
                                            icon: <AccountBookOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <ApartmentOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 1 In SubMenu',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: '3-3-1',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: '3-3-2',
                            icon: <AccountBookOutlined />,
                        },
                    ],
                },
            ],
        },
        {
            type: 'group',
            itemKey: '4',
            title: 'Item Group',
            items: [
                {
                    itemKey: '4-1',
                    title: 'Item 1 in Group',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '4-2',
                    title: 'Item 2 in Group',
                    icon: <CalendarOutlined />,
                },
            ],
        },
    ])
    </script>
    <template>
        <div style="width: 256px">
            <j-space align="center">
                <j-space align="center">
                    收起
                    <j-switch v-model:checked="inlineCollapsed" />
                </j-space>
                <j-space align="center">
                    主题
                    <j-switch
                        checked-children="D"
                        unchecked-children="L"
                        checked-value="dark"
                        unchecked-value="light"
                        v-model:checked="theme"
                    />
                </j-space>
            </j-space>
            <j-menu
                type="inline"
                v-model:selectedKeys="selectedKeys"
                v-model:openKeys="openKeys"
                :inlineCollapsed="inlineCollapsed"
                :items="items"
                :theme="theme"
                style="margin-top: 20px"
            ></j-menu>
        </div>
    </template>
    
    <script lang="jsx" setup>
    import { ref } from 'vue'
    import { AccountBookOutlined } from '@jview/icons-antd/es/AccountBookOutlined'
    import { CalendarOutlined } from '@jview/icons-antd/es/CalendarOutlined'
    import { ApartmentOutlined } from '@jview/icons-antd/es/ApartmentOutlined'
    import { AppstoreOutlined } from '@jview/icons-antd/es/AppstoreOutlined'
    
    const inlineCollapsed = ref(true)
    
    const theme = ref('dark')
    
    const openKeys = ref([])
    
    const selectedKeys = ref([])
    
    const items = ref([
        {
            itemKey: '1',
            title: 'Menu Item 1',
            icon: <AccountBookOutlined />,
        },
        {
            itemKey: '2',
            title: 'Menu Item 2',
            icon: <CalendarOutlined />,
        },
        {
            itemKey: '3',
            title: 'Sub Menu 1',
            icon: <ApartmentOutlined />,
            items: [
                {
                    itemKey: '3-1',
                    title: '3-1',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '3-2',
                    title: '3-2',
                    icon: <CalendarOutlined />,
                    items: [
                        {
                            itemKey: '3-2-1',
                            title: '3-2-1',
                            icon: <AppstoreOutlined />,
                            items: [
                                {
                                    itemKey: '3-2-1-1',
                                    title: '3-2-1-1',
                                    icon: <AppstoreOutlined />,
                                },
                                {
                                    itemKey: '3-2-1-2',
                                    title: '3-2-1-2',
                                    icon: <ApartmentOutlined />,
                                },
                                {
                                    type: 'group',
                                    itemKey: '3-2-1-3',
                                    title: 'Group In SubMenu 3-2-1',
                                    items: [
                                        {
                                            itemKey: '3-2-1-3-1',
                                            title: '3-2-1-3-1',
                                            icon: <AppstoreOutlined />,
                                        },
                                        {
                                            itemKey: '3-2-1-3-2',
                                            title: '3-2-1-3-2',
                                            icon: <AccountBookOutlined />,
                                        },
                                    ],
                                },
                            ],
                        },
                        {
                            itemKey: '3-2-2',
                            title: '3-2-2',
                            icon: <ApartmentOutlined />,
                        },
                    ],
                },
                {
                    type: 'group',
                    itemKey: '3-3',
                    title: 'Group 1 In SubMenu',
                    items: [
                        {
                            itemKey: '3-3-1',
                            title: '3-3-1',
                            icon: <CalendarOutlined />,
                        },
                        {
                            itemKey: '3-3-2',
                            title: '3-3-2',
                            icon: <AccountBookOutlined />,
                        },
                    ],
                },
            ],
        },
        {
            type: 'group',
            itemKey: '4',
            title: 'Item Group',
            items: [
                {
                    itemKey: '4-1',
                    title: 'Item 1 in Group',
                    icon: <AppstoreOutlined />,
                },
                {
                    itemKey: '4-2',
                    title: 'Item 2 in Group',
                    icon: <CalendarOutlined />,
                },
            ],
        },
    ])
    </script>
    参数说明类型默认值必填
    type菜单类型,支持 "vertical", "inline", "horizontal",默认是 "vertical""inline" | "horizontal" | "vertical"'vertical'
    items菜单子项配置Array<MenuItem | SubMenuItem | ItemGroup>
    theme主题配置,支持 "light" 和 "dark" 两种。"light" | "dark"'light'
    popupSubMenuTrigger弹出式子菜单的触发方式,默认 hover,即鼠标悬停时显示弹出的子菜单"click" | "hover"'hover'
    openKeys当前展开的菜单 key 组成的数组Array<string | number>
    selectedKeys当前选中的菜单 keysArray<string | number>
    inlineIndentinline 模式下子菜单的缩进值number24
    inlineCollapsedinline 模式下菜单是否收起到侧边boolean
    事件名说明回调类型
    select菜单选中时触发(key: string | number, selectedKeys: (string | number)[]) => void
    参数说明类型默认值必填
    title菜单标题string | VNode
    icon菜单图标VNode | ((item: MenuItem) => VNode)
    itemKey唯一标识string | number
    参数说明类型默认值必填
    title菜单标题string | VNode
    icon菜单图标VNode | ((item: SubMenuItem) => VNode)
    itemKey唯一标识string | number
    items菜单子项配置Array<MenuItem | SubMenuItem | ItemGroup>
    theme主题配置,默认继承自 menu。"light" | "dark"
    参数说明类型默认值必填
    title分组标题string | VNode
    itemKey唯一标识string | number
    items菜单组配置Array<MenuItem>