Skip to content

Popover 弹出框

用于在不打断用户流程的情况下展示补充信息和操作内容。支持标题 / 富文本内容 / 不同触发方式与位置控制。

何时使用

  • 需要在不打断用户流程的情况下展示补充信息和操作内容
  • 支持标题、富文本内容、不同触发方式与位置控制
  • 需要展示比 Tooltip 更复杂的内容和操作

基本使用

最简单的用法,默认点击触发显示弹出框。

悬停触发

trigger="hover" 鼠标悬停时显示弹出框。

自定义内容与标题插槽

#title / #content slot 可插入任意 VNode,常用于带操作按钮的富文本浮层。

12 个出现位置

通过 placement 控制方位。

自定义背景色 color

color 优先于 effect,接受任意 CSS color 字符串,常用于品牌色 / 警告色 / 渐变。

显隐箭头 show-arrow

通过 show-arrow 控制箭头显示/隐藏。

弹层宽度 width

width 控制弹层固定宽度,常用于复杂内容场景避免内容塌缩。

触发方式

hover / click / focus / manual / contextmenu 五种。

延迟显示 / 隐藏

通过 show-after / hide-after 控制显隐延迟(ms)。

受控显示 v-model:visible

visible 配合 v-model:visible 双向同步。

ref 调用 hide 方法

通过 ref 拿到组件实例后调用 hide() 可以在事件回调内主动关闭浮层,常用于「点确认后关闭」流程。

自动关闭

auto-close 设置毫秒数,弹层在指定时间后自动隐藏;常用于 toast-like 提示场景。

虚拟触发

virtual-triggering 配合 virtual-ref,让浮层挂在外部任意元素上,常用于「触发节点和声明位置分离」的场景。

业务场景:用户卡片 hover

用户列表上 hover 头像 / 名字时展示完整用户卡,是 IM / 协作工具最常见的悬浮卡片范式。

API

Popover Props

参数说明类型默认值
title标题文本,也可以通过 slot#title 传入string
content显示的内容,也可以通过 slot#content 传入string
placementPopover 的出现位置12 种方位字符串bottom
effect默认提供的主题'dark' | 'light'light
visible / v-model:visible受控显示状态booleanfalse
disabledPopover 是否可用booleanfalse
color自定义背景色(覆盖 effectstring
show-arrow是否显示箭头booleantrue
trigger触发方式'hover' | 'focus' | 'click' | 'manual' | 'contextmenu'click
show-after鼠标进入显示延迟(ms)number0
hide-after鼠标离开隐藏延迟(ms)number200
popper-class浮层根节点 classstring
fresh关闭后是否销毁内部内容booleanfalse
destroyTooltipOnHide隐藏时销毁弹层节点booleanfalse
autoAdjustOverflow自动调整方向避免溢出booleantrue
alignfloating-ui 微调对象object
offset出现位置的偏移量number4
raw-content是否将 content 作为 HTML 字符串处理booleanfalse
enterable鼠标是否可进入到 popover 中booleantrue
hide-on-click-outside是否在点击外部时隐藏booleantrue
close-on-esc是否支持 ESC 键关闭booleantrue
aria-label屏幕阅读器标签string
width弹层宽度number | string
transition定义渐变动画stringccui-popover-fade
auto-close自动关闭时间,单位毫秒number0
tabindexPopover 组件的 tabindexnumber | string0
teleported是否 Teleport 到 bodybooleantrue
persistent是否持久化booleantrue
virtual-triggering是否启用虚拟触发器booleanfalse
virtual-ref虚拟触发器的参照元素HTMLElement
trigger-keys键盘触发按键string[]['Enter', 'Space']

Popover Events

事件名说明回调参数
before-show显示前触发
show显示时触发
before-hide隐藏前触发
hide隐藏时触发
update:visiblev-model:visible 同步visible
before-enter显示动画播放前触发
after-enter显示动画播放后触发
before-leave隐藏动画播放前触发
after-leave隐藏动画播放后触发

Popover Slots

插槽名说明
defaultPopover 触发 & 引用的元素
title自定义标题
content自定义内容

Popover Exposes

方法名说明类型
hide隐藏弹出框() => void

Released under the MIT License.