Dropdown 下拉菜单
将动作或菜单折叠到下拉菜单中。
基础用法
悬停在下拉菜单上以展开更多操作。
<script setup>
import { h } from 'vue'
import Dropdown from '@/components/Dropdown/Dropdown.vue'
import Button from '@/components/Button/Button.vue'
const options = [
{ key: 1, label: h('b', 'this is bold') },
{ key: 2, label: 'item2', disabled: true },
{ key: 3, label: 'item3', divided: true },
{ key: 4, label: 'item4' }
]
</script>
<template>
<div class="basic block">
<Dropdown
placement="bottom"
:menu-options="options"
>
<Button type="primary"> Hover 下拉菜单 </Button>
</Dropdown>
</div>
</template>
<style>
.vp-doc .vitepress-demo-preview-preview ul, .vp-doc .vitepress-demo-preview-preview ol {
list-style-type: none;
margin: 0;
padding: 0;
}
</style>
触发方式
可以配置点击激活或者悬停激活。
将 trigger 属性设置为 click 即可, 默认为 hover。
<script setup>
import { h } from 'vue'
import Dropdown from '@/components/Dropdown/Dropdown.vue'
import Button from '@/components/Button/Button.vue'
const options = [
{ key: 1, label: h('b', 'this is bold') },
{ key: 2, label: 'item2', disabled: true },
{ key: 3, label: 'item3', divided: true },
{ key: 4, label: 'item4' }
]
</script>
<template>
<div class="basic block">
<Dropdown
placement="bottom"
:menu-options="options"
trigger="click"
>
<Button type="primary"> 点击触发下拉菜单 </Button>
</Dropdown>
</div>
</template>
手动打开关闭
将 manual 属性设置为 true 即可, 然后可以使用实例上面的 show 和 hide 方法打开关闭下拉菜单。
<script setup>
import { h, ref } from 'vue'
import Dropdown from '@/components/Dropdown/Dropdown.vue'
import Button from '@/components/Button/Button.vue'
const options = [
{ key: 1, label: h('b', 'this is bold') },
{ key: 2, label: 'item2', disabled: true },
{ key: 3, label: 'item3', divided: true },
{ key: 4, label: 'item4' }
]
const tooltipRef = ref()
const open = () => {
tooltipRef.value?.show()
}
const close = () => {
tooltipRef.value?.hide()
}
</script>
<template>
<div class="basic block">
<Dropdown
placement="bottom"
:menu-options="options"
trigger="click"
manual
ref="tooltipRef"
>
<Button> 菜单容器 </Button>
</Dropdown>
<br/><br/>
<Button type="primary" @click="open"> 点击手动触发显示 </Button>
<Button type="danger" @click="close"> 点击手动触发隐藏 </Button>
</div>
</template>