Dropdown下拉菜单·续1
<template> <a-dropdown> <a class="ant-dropdown-link" @click.prevent> Hover me, Click menu item <DownOutlined /> </a> <template #overlay> <a-menu @click="onClick"> <a-menu-item key="1">1st menu item</a-menu-item> <a-menu-item key="2">2nd menu item</a-menu-item> <a-menu-item key="3">3rd menu item</a-menu-item> </a-menu> </template> </a-dropdown></template><script lang="ts">import { defineComponent, 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 onClick = ({ key }: MenuInfo) => { console.log(`Click on item ${key}`); }; return { onClick, }; }, components: { DownOutlined, },});</script>
Hover me
菜单隐藏方式
默认是点击关闭菜单,可以关闭此功能。
<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>
Cascading menu
多级菜单
传入的菜单里有多个层级。
<template> <a-dropdown> <a class="ant-dropdown-link" @click.prevent> Cascading menu <DownOutlined /> </a> <template #overlay> <a-menu> <a-menu-item>1st menu item</a-menu-item> <a-menu-item>2nd menu item</a-menu-item> <a-sub-menu key="test" title="sub menu"> <a-menu-item>3rd menu item</a-menu-item> <a-menu-item>4th menu item</a-menu-item> </a-sub-menu> <a-sub-menu title="disabled sub menu" disabled> <a-menu-item>5d menu item</a-menu-item> <a-menu-item>6th menu item</a-menu-item> </a-sub-menu> </a-menu> </template> </a-dropdown></template><script lang="ts">import { defineComponent } from 'vue';import { DownOutlined } from '@ant-design/icons-vue';export default defineComponent({ components: { DownOutlined, },});</script>
API
属性如下
| disabled |
菜单是否禁用 |
boolean |
- |
|
|
|
|
| getPopupContainer |
菜单渲染父节点。默认渲染到 body 上,如果你遇到菜单滚动定位问题,试试修改为滚动的区域,并相对其定位。 |
Function(triggerNode) |
() => document.body |
|
|
|
|
| overlay(v-slot) |
菜单 |
Menu |
- |
|
|
|
|
| overlayClassName |
下拉根元素的类名称 |
string |
- |
|
|
|
|
| overlayStyle |
下拉根元素的样式 |
object |
- |
|
|
|
|
| placement |
菜单弹出位置:bottomLeft bottomCenter bottomRight topLeft topCenter topRight |
String |
bottomLeft |
|
|
|
|
| trigger | 触发下拉的行为, 移动端不支持 hover | Array<click|hover|contextmenu> | [‘hover’] |
|---|---|---|---|
| visible(v-model) |
菜单是否显示 |
boolean |
- |
|
|
|
|
overlay 菜单使用 Menu,还包括菜单项 Menu.Item,分割线 Menu.Divider。
注意: Menu.Item 必须设置唯一的 key 属性。
Dropdown 下的 Menu 默认不可选中。如果需要菜单可选中,可以指定 <Menu selectable>.
事件
| visibleChange |
菜单显示状态改变时调用,参数为 visible |
function(visible) |
|
|
|
| disabled |
菜单是否禁用 |
boolean |
- |
|
|
|
|
|
|
| icon | 右侧的 icon | VNode | slot | - | 1.5.0 |
|---|---|---|---|---|
| overlay(v-slot) |
菜单 |
Menu |
- |
|
|
|
|
|
|
| placement |
菜单弹出位置:bottomLeft bottomCenter bottomRight topLeft topCenter topRight |
String |
bottomLeft |
|
|
|
|
|
|
| size |
按钮大小,和 Button 一致 |
string |
‘default’ |
|
|
|
|
|
|
| trigger | 触发下拉的行为 | Array<click|hover|contextmenu> | [‘hover’] | |
|---|---|---|---|---|
| type |
按钮类型,和 Button 一致 |
string |
‘default’ |
|
|
|
|
|
|
| visible(v-model) |
菜单是否显示 |
boolean |
- |
|
|
|
|
|
|
| click |
点击左侧按钮的回调,和 Button 一致 |
Function |
|
|
|
| visibleChange |
菜单显示状态改变时调用,参数为 visible |
function(visible) |
|
|
|