Skip to content

Tooltip 文字提示 ​

基礎用法 ​

vue
<template>
  <lh-tooltip content="这是提示文案">
    <lh-button>点击查看提示</lh-button>
  </lh-tooltip>
</template>

小程序沒有 hover 語義

trigger 預設是 click(全端可用)。hover 僅 H5 有效—— 小程序端請用 trigger="click",透過點選 / 觸碰觸發與關閉。

位置與寬度 ​

vue
<template>
  <lh-tooltip content="底部提示" placement="bottom">
    <lh-button>bottom</lh-button>
  </lh-tooltip>

  <lh-tooltip content="长文案会自动换行" :max-width="200" placement="top">
    <lh-button>限制宽度</lh-button>
  </lh-tooltip>
</template>

Props ​

屬性說明類型預設值
content提示文案string—
placement彈層位置(12 種方位)LhTooltipPlacementCore'top'
trigger觸發方式:click(全端)/ hover(僅 H5)'click' | 'hover''click'
showDelay顯示延遲(毫秒)number—
hideDelay隱藏延遲(毫秒)number—
maxWidth最大寬度(內容自動換行)string | number—
disabled停用booleanfalse
customClass自訂類別名string—
themeVars元件級主題變數Record<string, string>—
sx快速版面配置屬性LhSxProps—

Events ​

事件說明回呼參數
update:modelValue顯隱變化(受控用法)(visible: boolean)
show顯示—
hide隱藏—

與 Vue3 版的差異

  • 彈層走 root-portal + 兩幀非同步度量定位(先透明渲染量尺寸 → 定位 → 顯示,防閃爍)。
  • MP 端 showDelay / hideDelay 僅 click 模式下保留立即行為。
  • 定位計算是非同步的(getLhRect 傳回 Promise),不能假設同步拿到結果。