mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 05:29:01 +08:00
8ab50b1757
* fix(menu): icon do not show problem * fix(menu): icon do not show problem * feat(menu): update demo * test(menu): update demo snap * chore(Menu): update docs * test(Menu): update demo * Update MenuItem.tsx * Update SubMenu.tsx --------- Co-authored-by: tangjinzhou <415800467@qq.com>
96 lines
2.1 KiB
Vue
96 lines
2.1 KiB
Vue
<docs>
|
|
---
|
|
order: 5
|
|
title:
|
|
zh-CN: 切换菜单类型
|
|
en-US: Switch the menu type
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
展示动态切换模式。
|
|
|
|
## en-US
|
|
|
|
Show the dynamic switching mode (between `inline` and `vertical`).
|
|
|
|
</docs>
|
|
|
|
<template>
|
|
<div>
|
|
<a-switch :checked="state.mode === 'vertical'" @change="changeMode" />
|
|
Change Mode
|
|
<span class="ant-divider" style="margin: 0 1em" />
|
|
<a-switch :checked="state.theme === 'dark'" @change="changeTheme" />
|
|
Change Theme
|
|
<br />
|
|
<br />
|
|
<a-menu
|
|
v-model:openKeys="state.openKeys"
|
|
v-model:selectedKeys="state.selectedKeys"
|
|
style="width: 256px"
|
|
:mode="state.mode"
|
|
:items="items"
|
|
:theme="state.theme"
|
|
></a-menu>
|
|
</div>
|
|
</template>
|
|
<script lang="ts" setup>
|
|
import { h, reactive } from 'vue';
|
|
import {
|
|
MailOutlined,
|
|
CalendarOutlined,
|
|
AppstoreOutlined,
|
|
SettingOutlined,
|
|
} from '@ant-design/icons-vue';
|
|
import type { MenuMode, MenuTheme } from 'ant-design-vue';
|
|
import { ItemType } from 'ant-design-vue';
|
|
|
|
const state = reactive({
|
|
mode: 'inline' as MenuMode,
|
|
theme: 'light' as MenuTheme,
|
|
selectedKeys: ['1'],
|
|
openKeys: ['sub1'],
|
|
});
|
|
|
|
function getItem(
|
|
label: string,
|
|
key: string,
|
|
icon?: any,
|
|
children?: ItemType[],
|
|
type?: 'group',
|
|
): ItemType {
|
|
return {
|
|
key,
|
|
icon,
|
|
children,
|
|
label,
|
|
type,
|
|
} as ItemType;
|
|
}
|
|
|
|
const items: ItemType[] = reactive([
|
|
getItem('Navigation One', '1', h(MailOutlined)),
|
|
getItem('Navigation Two', '2', h(CalendarOutlined)),
|
|
getItem('Navigation Two', 'sub1', h(AppstoreOutlined), [
|
|
getItem('Option 3', '3'),
|
|
getItem('Option 4', '4'),
|
|
getItem('Submenu', 'sub1-2', null, [getItem('Option 5', '5'), getItem('Option 6', '6')]),
|
|
]),
|
|
getItem('Navigation Three', 'sub2', h(SettingOutlined), [
|
|
getItem('Option 7', '7'),
|
|
getItem('Option 8', '8'),
|
|
getItem('Option 9', '9'),
|
|
getItem('Option 10', '10'),
|
|
]),
|
|
]);
|
|
|
|
const changeMode = (checked: boolean) => {
|
|
state.mode = checked ? 'vertical' : 'inline';
|
|
};
|
|
|
|
const changeTheme = (checked: boolean) => {
|
|
state.theme = checked ? 'dark' : 'light';
|
|
};
|
|
</script>
|