警告提示,展现需要关注的信息。
何时使用
代码演示
Tooltip will show when mouse enter.
基本用法
最简单的用法。
<template> <a-tooltip> <template #title>prompt text</template> Tooltip will show when mouse enter. </a-tooltip></template>
箭头指向
设置了 arrowPointAtCenter 后,箭头将指向目标元素的中心。
<template> <a-space> <a-tooltip placement="topLeft" title="Prompt Text"> <a-button>Align edge / 边缘对齐</a-button> </a-tooltip> <a-tooltip placement="topLeft" title="Prompt Text" arrow-point-at-center> <a-button>Arrow points to center / 箭头指向中心</a-button> </a-tooltip> </a-space></template>
位置
位置有 12 个方向。
<template> <div id="components-a-tooltip-demo-placement"> <div :style="{ marginLeft: `${buttonWidth}px`, whiteSpace: 'nowrap' }"> <a-tooltip placement="topLeft"> <template #title> <span>prompt text</span> </template> <a-button>TL</a-button> </a-tooltip> <a-tooltip placement="top"> <template #title> <span>prompt text</span> </template> <a-button>Top</a-button> </a-tooltip> <a-tooltip placement="topRight"> <template #title> <span>prompt text</span> </template> <a-button>TR</a-button> </a-tooltip> </div> <div :style="{ width: `${buttonWidth}px`, float: 'left' }"> <a-tooltip placement="leftTop"> <template #title> <span>prompt text</span> </template> <a-button>LT</a-button> </a-tooltip> <a-tooltip placement="left"> <template #title> <span>prompt text</span> </template> <a-button>Left</a-button> </a-tooltip> <a-tooltip placement="leftBottom"> <template #title> <span>prompt text</span> </template> <a-button>LB</a-button> </a-tooltip> </div> <div :style="{ width: `${buttonWidth}px`, marginLeft: `${buttonWidth * 4 + 24}px` }"> <a-tooltip placement="rightTop"> <template #title> <span>prompt text</span> </template> <a-button>RT</a-button> </a-tooltip> <a-tooltip placement="right"> <template #title> <span>prompt text</span> </template> <a-button>Right</a-button> </a-tooltip> <a-tooltip placement="rightBottom"> <template #title> <span>prompt text</span> </template> <a-button>RB</a-button> </a-tooltip> </div> <div :style="{ marginLeft: `${buttonWidth}px`, clear: 'both', whiteSpace: 'nowrap' }"> <a-tooltip placement="bottomLeft"> <template #title> <span>prompt text</span> </template> <a-button>BL</a-button> </a-tooltip> <a-tooltip placement="bottom"> <template #title> <span>prompt text</span> </template> <a-button>Bottom</a-button> </a-tooltip> <a-tooltip placement="bottomRight"> <template #title> <span>prompt text</span> </template> <a-button>BR</a-button> </a-tooltip> </div> </div></template><script lang="ts">import { defineComponent } from 'vue';export default defineComponent({ setup() { return { buttonWidth: 70, }; },});</script><style scoped>#components-a-tooltip-demo-placement .ant-btn { width: 70px; text-align: center; padding: 0; margin-right: 8px; margin-bottom: 8px;}</style>
自动调整位置
气泡框不可见时自动调整位置。
<template> <div :style="wrapStyles"> <a-tooltip placement="left" title="Prompt Text" :get-popup-container="getPopupContainer"> <a-button>Adjust automatically / 自动调整</a-button> </a-tooltip> <br /> <a-tooltip placement="left" title="Prompt Text" :get-popup-container="getPopupContainer" :auto-adjust-overflow="false" > <a-button style="margin-top: 10px">Ingore / 不处理</a-button> </a-tooltip> </div></template><script lang="ts">import { defineComponent } from 'vue';const wrapStyles: Record<string, string> = { overflow: 'hidden', position: 'relative', padding: '24px', border: '1px solid #e9e9e9',};export default defineComponent({ setup() { const getPopupContainer = (trigger: HTMLElement) => { return trigger.parentElement; }; return { wrapStyles, getPopupContainer, }; },});</script>
API
| title | 提示文字 | string|slot | 无 |
|---|---|---|---|
共同的 API
以下 API 为 Tooltip、Popconfirm、Popover 共享的 API。
| arrowPointAtCenter |
箭头是否指向目标元素中心 |
boolean |
false |
|
|
|
|
| autoAdjustOverflow |
气泡被遮挡时自动调整位置 |
boolean |
true |
|
|
|
|
| defaultVisible |
默认是否显隐 |
boolean |
false |
|
|
|
|
| getPopupContainer |
浮层渲染父节点,默认渲染到 body 上 |
Function(triggerNode) |
() => document.body |
|
|
|
|
| mouseEnterDelay |
鼠标移入后延时多少才显示 Tooltip,单位:秒 |
number |
0 |
|
|
|
|
| mouseLeaveDelay |
鼠标移出后延时多少才隐藏 Tooltip,单位:秒 |
number |
0.1 |
|
|
|
|
| overlayClassName |
卡片类名 |
string |
无 |
|
|
|
|
| overlayStyle |
卡片样式 |
object |
无 |
|
|
|
|
| placement |
气泡框位置,可选 top left right bottom topLeft topRight bottomLeft bottomRight leftTop leftBottom rightTop rightBottom |
string |
top |
|
|
|
|
| trigger |
触发行为,可选 hover/focus/click/contextmenu |
string |
hover |
|
|
|
|
| visible(v-model) |
用于手动控制浮层显隐 |
boolean |
false |
|
|
|
|
| destroyTooltipOnHide |
隐藏后是否销毁 tooltip |
boolean |
false |
|
|
|
|
| align |
该值将合并到 placement 的配置中,设置参考 dom-align |
Object |
无 |
|
|
|
|
事件
| visibleChange |
显示隐藏的回调 |
(visible) => void |
|
|
|
注意
请确保 Tooltip 的子元素能接受 mouseenter、mouseleave、focus、click 事件。