Skip to content

t-action-menu

ActionMenu 操作菜单

组件介绍

t-action-menu 用于从页面底部弹出一组操作内容,适合分享菜单、操作列表、快捷入口等场景。组件本身不限制菜单内容结构,主要通过插槽承载内容,因此在简单列表、图文宫格、分页分享面板等布局里都能复用。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

基础用法参考 demo/action-menu/action-menu.uvue,通过 button 插槽定义触发按钮,通过默认插槽放置菜单内容。

vue
<t-action-menu title="请选择" button-text="取消">
  <template v-slot:button>
    <t-button type="primary" class="mb-30">菜单</t-button>
  </template>

  <t-col class="mtb-20">
    <t-row :class="[`tpl fc tvg mb-2px`]" :hover="true" v-for="i in 3">
      <text>选项{{i}}</text>
    </t-row>
  </t-col>
</t-action-menu>

如果你希望做成分享面板,可以在默认插槽中继续放 swiper、图标列表或任意自定义布局:

vue
<t-action-menu title="分享到" :content-class="`trm-lr`" button-text="取消">
  <template v-slot:button>
    <t-button type="error" class="mb-30">分享</t-button>
  </template>

  <t-row :class="`mtb-10 tvg`">
    <swiper style="height: 200rpx;width:100%;">
      <swiper-item style="display: flex;flex-direction: row;align-items: center;justify-content: center;">
        <t-col class="faic mlbr-40">
          <image class="twh-60 mb-10" src="/static/image/qq.png"></image>
          <text>QQ</text>
        </t-col>
      </swiper-item>
    </swiper>
  </t-row>
</t-action-menu>

Props

属性名说明类型默认值
path点击组件后跳转的页面路径;为空时仅响应事件string''
hover是否启用点击效果booleanfalse
type组件主题类型,可选 infoprimaryerrorwarningsuccessstring''
disabled是否禁用booleanfalse
effect组件显示主题,可选 normaldarklightplainstring'normal'
size组件尺寸,可选 largemediumsmallministring'medium'
title菜单顶部标题文本string'标题'
buttonText底部取消区域文本string'取消'
contentClass内容容器自定义样式类,对应外部类 content-classany''

Events

源码中通过 defineEmits 暴露了以下事件:

事件名说明回调参数
click点击时触发-
transitionend动画结束时触发-
initFinished组件初始化完成时触发,返回组件节点信息-

说明:当前 t-action-menu 自身源码没有直接绑定这几个事件的触发逻辑,更多是作为公共组件事件约定保留在文档注释中。如果你后续继续完善源码实现,文档这里也建议同步更新。

Slots

插槽名说明
default菜单主体内容区域,用来放操作项、自定义列表、分享布局等
button触发弹出的按钮区域,常用于放置 t-button

Methods

组件通过 defineExpose 暴露了以下实例方法:

方法名说明
show调用内部 t-popupshow 方法,用于切换菜单显示状态

可以通过 ref 获取组件实例后手动控制显示:

vue
<template>
  <t-action-menu ref="actionMenuRef" title="请选择">
    <template v-slot:button>
      <t-button @click="openMenu">打开菜单</t-button>
    </template>
    <t-col>
      <text>自定义内容</text>
    </t-col>
  </t-action-menu>
</template>

<script setup>
const actionMenuRef = ref<ComponentPublicInstance | null>(null)

function openMenu() {
  actionMenuRef.value?.$callMethod('show')
}
</script>