Skip to content

Dropdown 下拉菜单

悬浮下拉菜单控件,支持自定义触发器、多方向定位 (bottom-left | bottom-right | top-left | top-right)、分割线、危险操作红字与暗黑模式。


代码示例

1. 微信同款右上角加号菜单 (Bottom Right)

vue
<template>
  <mu-dropdown :items="wechatItems" placement="bottom-right" width="300rpx" @click="onSelect">
    <view class="icon-btn">
      <mu-icon name="plus" :size="20" color="#171717" />
    </view>
  </mu-dropdown>
</template>

<script setup>
import { ref } from 'vue'

const wechatItems = ref([
  { text: '发起群聊', icon: 'users' },
  { text: '添加朋友', icon: 'user-plus' },
  { text: '扫一扫', icon: 'maximize', divider: true },
  { text: '收付款', icon: 'credit-card', danger: true }
])

const onSelect = ({ item }) => {
  console.log('选中菜单:', item.text)
}
</script>

2. 向上弹出菜单 (Top Placement)

vue
<template>
  <mu-dropdown :items="menuItems" placement="top-left" @click="onSelect">
    <mu-button type="info" plain radius="full">向上展开 ▴</mu-button>
  </mu-dropdown>
</template>

<script setup>
import { ref } from 'vue'

const menuItems = ref([
  { text: '编辑项目', icon: 'edit' },
  { text: '复制链接', icon: 'copy' },
  { text: '删除记录', icon: 'trash-2', danger: true }
])
</script>

API 属性说明 (Props)

参数名说明类型可选值默认值
items下拉菜单列表集合 [{ text, icon, color, danger, divider, disabled }]Array-[]
placement菜单悬浮弹出定位Stringbottom-left | bottom-right | top-left | top-right'bottom-left'
width下拉面板宽度String-'280rpx'

菜单项数据结构 (Item Object)

字段名说明类型
text / label菜单文字String
icon矢量图标名称String
color文字色彩String
iconColor图标色彩String
danger是否标红危险警示项Boolean
divider是否在下方展示分割线Boolean
disabled是否禁用不可点击Boolean

事件说明 (Events)

事件名说明回调参数
click / select点击菜单项时触发({ index: Number, item: Object })
open下拉面板展开时触发-
close下拉面板关闭时触发-

插槽说明 (Slots)

插槽名说明
default触发下拉菜单展开的点击按键/宿主节点插槽

实例方法 (Expose Methods)

获取组件 ref 实例后可直接调用以下公开方法:

方法名说明
toggle()切换下拉菜单展开/收起状态
visible当前菜单是否展开(只读 ref)

基于 MIT 协议开源发行

H5 模拟器 (dropdown)☀️🔄