ant-design-vue/components/dropdown/demo/overlay-visible.vue

62 lines
1.3 KiB
Vue
Raw Normal View History

2021-09-01 07:04:46 +00:00
<docs>
---
order: 7
title:
zh-CN: 菜单隐藏方式
en-US: The way of hiding menu.
---
## zh-CN
默认是点击关闭菜单可以关闭此功能
## en-US
The default is to close the menu when you click on menu items, this feature can be turned off.
</docs>
<template>
<a-dropdown v-model:visible="visible">
<a class="ant-dropdown-link" @click.prevent>
Hover me
<DownOutlined />
</a>
<template #overlay>
<a-menu @click="handleMenuClick">
<a-menu-item key="1">Clicking me will not close the menu.</a-menu-item>
<a-menu-item key="2">Clicking me will not close the menu also.</a-menu-item>
<a-menu-item key="3">Clicking me will close the menu</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
<script lang="ts">
import { defineComponent, ref, VNodeChild } from 'vue';
import { DownOutlined } from '@ant-design/icons-vue';
interface MenuInfo {
key: string;
keyPath: string[];
item: VNodeChild;
domEvent: MouseEvent;
}
export default defineComponent({
setup() {
const visible = ref(false);
const handleMenuClick = (e: MenuInfo) => {
if (e.key === '3') {
visible.value = false;
}
};
return {
visible,
handleMenuClick,
};
},
components: {
DownOutlined,
},
});
</script>