Tooltip 文字提示

常用于展示鼠标 hover 时的提示信息。

基础用法

在这里我们提供 9 种不同方向的展示方式,可以通过以下完整示例来理解,选择你要的效果。

主题

Tooltip 组件提供了两个不同的主题:darklight

TIP

要使用自定义主题,您必须知道您的工具提示在哪里渲染, 如果您的工具提示被呈现为根元素,您将需要全局设置css规则。

建议您使用自定义主题并同时显示箭头时不使用线性渐变背景颜色。 因为弹出箭头和内容是两个不同的元素, 弹出箭头的样式需要单独设置, 当它到渐变背景颜色时,会看起来很奇怪。

更多内容的文字提示

展示多行文本或者是设置文本内容的格式

高级扩展

除了这些基本设置外,还有一些属性可以让使用者更好的定制自己的效果:

transition 属性可以定制显隐的动画效果,默认为fade-in-linear

如果需要关闭 tooltip 功能,disabled 属性可以满足这个需求, 你只需要将其设置为 true

事实上,Tooltip 是一个基于 ElPopper 的扩展,您可以使用 ElPopper 中允许的任何属性。

TIP

Tooltip 内不支持 router-link 组件,请使用 vm.$router.push 代替。

tooltip 内不支持 disabled form 元素,参考 MDN, 请在 disabled form 元素外层添加一层包裹元素。

显示 HTML 内容

内容属性可以设置为 HTML 字符串。

WARNING

content 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 XSS 攻击。 因此在 raw-content 打开的情况下,请确保 content 的内容是可信的,永远不要将用户提交的内容赋值给 content 属性。

虚拟触发

有时候我们想把 tooltip 的触发元素放在别的地方,而不需要写在一起,这时候就可以使用虚拟触发。

TIP

需要注意的是,虚拟触发的 tooltip 是受控组件,因此你必须自己去控制 tooltip 是否显示,你将无法通过点击空白处来关闭 tooltip。

单例模式

Tooltip 可以作为单例,也就是是说你可以同时有多个触发同一个 tooltip 的触发元素,这个功能是在 虚拟触发 的基础上开发的。

TIP

已知问题:当使用单例模式时,tooltip 的触发元素发生改变的时候可能会发生弹跳。

受控模式

Tooltip 可以通过父组件使用 v-model:visible 来控制它的显示与关闭。

自定义动画

工具提示可以自定义动画,您可以按照自己的愿望设置所需的动画功能。

属性

属性说明类型可选值默认值
append-to指示 Tooltip 的内容将附加在哪一个网页元素上CSSSelector \HTMLElement
effectTooltip theme, built-in theme: dark / lightstringstringdark
contentdisplay content, can be overridden by slot#contentString
raw-contentwhether content is treated as HTML stringbooleanfalse
placementposition of Tooltipstringtop/top-start/top-end/bottom/bottom-start/bottom-end/left/left-start/left-end/right/right-start/right-endbottom
visible / v-model:visiblevisibility of Tooltipbooleanfalse
disabledwhether Tooltip is disabledbooleanfalse
offsetoffset of the Tooltipnumber0
transitionanimation namestringel-fade-in-linear
visible-arrow (will deprecate in 2.1.0 )whether an arrow is displayed. For more information, check ElPopper pagebooleantrue
popper-optionspopper.js parametersObjectrefer to popper.js doc{ boundariesElement: 'body', gpuAcceleration: false }
show-afterdelay of appearance, in millisecondnumber0
show-arrowwhether the tooltip content has an arrowbooleantrue / falsetrue
hide-afterdelay of disappear, in millisecondnumber0
auto-closetimeout in milliseconds to hide tooltipnumber0
manualwhether to control Tooltip manually. mouseenter and mouseleave won't have effects if set to truebooleanfalse
popper-classcustom class name for Tooltip's popperstring
enterablewhether the mouse can enter the tooltipBooleantrue
tabindextabindex of Tooltipnumber0
teleportedwhether tooltip content is teleported, if true it will be teleported to where append-to setsbooleantrue / falsetrue
triggerHow should the tooltip be triggered (to show)stringhover / click / focus / contextmenuhover
virtual-triggeringIndicates whether virtual triggering is enabledbooleanfalse
virtual-refIndicates the reference element to which the tooltip is attachedHTMLElement

插槽

插槽名说明
Tooltip 触发 & 引用的元素
content自定义内容