You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/menu/demo/theme.vue

132 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 4
title:
zh-CN: 主题
en-US: Menu Themes
---
## zh-CN
内建了两套主题 `light` `dark`默认 `light`
## en-US
There are two built-in themes: `light` and `dark`. The default value is `light`.
</docs>
<template>
<div>
<a-switch
:checked="theme === 'dark'"
checked-children="Dark"
un-checked-children="Light"
@change="changeTheme"
/>
<br />
<br />
<a-menu
v-model:openKeys="openKeys"
v-model:selectedKeys="selectedKeys"
style="width: 256px"
mode="inline"
:theme="theme"
:items="items"
/>
</div>
</template>
<script lang="ts" setup>
import { h, ref } from 'vue';
import {
MailOutlined,
CalendarOutlined,
AppstoreOutlined,
SettingOutlined,
} from '@ant-design/icons-vue';
import type { MenuTheme } from 'ant-design-vue';
const theme = ref<MenuTheme>('dark');
const selectedKeys = ref(['1']);
const openKeys = ref(['sub1']);
const items = ref([
{
key: '1',
icon: () => h(MailOutlined),
label: 'Navigation One',
title: 'Navigation One',
},
{
key: '2',
icon: () => h(CalendarOutlined),
label: 'Navigation Two',
title: 'Navigation Two',
},
{
key: 'sub1',
icon: () => h(AppstoreOutlined),
label: 'Navigation Three',
title: 'Navigation Three',
children: [
{
key: '3',
label: 'Option 3',
title: 'Option 3',
},
{
key: '4',
label: 'Option 4',
title: 'Option 4',
},
{
key: 'sub1-2',
label: 'Submenu',
title: 'Submenu',
children: [
{
key: '5',
label: 'Option 5',
title: 'Option 5',
},
{
key: '6',
label: 'Option 6',
title: 'Option 6',
},
],
},
],
},
{
key: 'sub2',
icon: () => h(SettingOutlined),
label: 'Navigation Four',
title: 'Navigation Four',
children: [
{
key: '7',
label: 'Option 7',
title: 'Option 7',
},
{
key: '8',
label: 'Option 8',
title: 'Option 8',
},
{
key: '9',
label: 'Option 9',
title: 'Option 9',
},
{
key: '10',
label: 'Option 10',
title: 'Option 10',
},
],
},
]);
const changeTheme = (checked: boolean) => {
theme.value = checked ? 'dark' : 'light';
};
</script>