跳转到内容

触发器 Trigger

设置align-point属性,可以使弹出层出现在鼠标位置。

通过show-arrow属性,可以展示默认的箭头元素。也可以通过arrow-classarrow-style进行定制。

这个例子展示了触发器的最基础的使用。触发器默认是没有弹出框的样式的。以下示例均为官网添加的样式。

弹出层可以嵌套在另一个弹出层内。

通过设置 update-at-scroll 监听容器的滚动。

通过popup-translate属性,可以设置弹窗在原本位置的基础上进行额外的位置调整。

通过trigger传入数组,可以设置多个触发方式。

参数名描述类型默认值版本
popup-visible (v-model)弹出框是否可见boolean-
default-popup-visible弹出框默认是否可见(非受控模式)booleanfalse
trigger触发方式'hover' | 'click' | 'focus' | 'contextMenu''hover'
position弹出位置'top' | 'tl' | 'tr' | 'bottom' | 'bl' | 'br' | 'left' | 'lt' | 'lb' | 'right' | 'rt' | 'rb''bottom'
disabled触发器是否禁用booleanfalse
popup-offset弹出框的偏移量(弹出框距离触发器的偏移距离)number0
popup-translate弹出框的移动距离TriggerPopupTranslate-
show-arrow弹出框是否显示箭头booleanfalse
align-point弹出框是否跟随鼠标booleanfalse
popup-hover-stay是否在移出触发器,并移入弹出框时保持弹出框显示booleantrue
blur-to-close是否在触发器失去焦点时关闭弹出框booleantrue
click-to-close是否在点击触发器时关闭弹出框booleantrue
click-outside-to-close是否在点击外部区域时关闭弹出框booleantrue
unmount-on-close是否在关闭时卸载弹出框节点booleantrue
content-class弹出框内容的类名string|array|object-
content-style弹出框内容的样式CSSProperties-
arrow-class弹出框箭头的类名string|array|object-
arrow-style弹出框箭头的样式CSSProperties-
popup-style弹出框的样式CSSProperties-
animation-name弹出动画的namestring'fade-in'
duration弹出动画的持续时间number| { enter: number; leave: number; }-
mouse-enter-delaymouseenter事件延时触发的时间(毫秒)number100
mouse-leave-delaymouseleave事件延时触发的时间(毫秒)number100
focus-delayfocus事件延时触发的时间(毫秒)number0
auto-fit-popup-width是否将弹出框宽度设置为触发器宽度booleanfalse
auto-fit-popup-min-width是否将弹出框的最小宽度设置为触发器宽度booleanfalse
auto-fix-position当触发器的尺寸发生变化时,是否重新计算弹出框位置booleantrue
popup-container弹出框的挂载容器string | HTMLElement-
update-at-scroll是否在容器滚动时更新弹出框的位置booleanfalse
auto-fit-position是否自动调整弹出框位置,以适应窗口大小booleantrue
render-to-body是否挂载在 body 元素下booleantrue
prevent-focus是否阻止弹出层中的元素点击时获取焦点booleanfalse
scroll-to-close是否在滚动时关闭弹出框booleanfalse2.46.0
scroll-to-close-distance滚动阈值,当滚动距离超过该值时触发关闭number0
事件名描述参数版本
popup-visible-change弹出框显示状态改变时触发visible: boolean
show弹出框显示后(动画结束)触发-2.18.0
hide弹出框隐藏后(动画结束)触发-2.18.0
插槽名描述参数
content弹出框内容-
type TriggerPopupTranslate = [number, number] | { [key in TriggerPosition]?: [number, number] };

弹出框默认是挂载到 body 元素上的,如果想要修改挂载元素,可以使用 popup-container 属性进行指定,同时需要注意保证挂载元素的位置可以被准确定位到,一般可以为挂载元素增加 position: relative 样式。

在微前端项目中,需要保证子应用的挂载位置准确,可以将子应用的 body 样式添加 position: relative

组件默认仅监听了 window 的滚动事件,对于内部 div 的滚动没有进行监听,类似 scroll-to-close 功能也仅会对 window 滚动生效。可以通过开启 update-at-scroll 属性支持对父级 div 元素的滚动事件监听。