Skip to content

Tooltip 文字提示 ​

`tooltip` · 反馈与浮层

纯文字气泡。PC 端 hover 触发且进出都带延迟(防鼠标轨迹穿越时闪烁),移动端长按或点击触发。

用法 ​

实时预览 · 真实组件
vue
<view class="row">
  <cd-tooltip content="这是一段提示文字,PC 悬停 / 移动长按都能唤出">
    <cd-button size="small">悬停或长按我(top)</cd-button>
  </cd-tooltip>
  <cd-tooltip content="右侧方位" placement="right">
    <cd-button size="small">placement: right</cd-button>
  </cd-tooltip>
  <cd-tooltip content="底部方位" placement="bottom">
    <cd-button size="small">placement: bottom</cd-button>
  </cd-tooltip>
</view>
<view class="row">
  <cd-popover v-model="popoverVisible" title="确认发布" placement="bottom">
    <template #reference>
      <cd-button size="small" type="primary">点击弹出 popover</cd-button>
    </template>
    <view class="popover-demo">
      <text class="popover-demo__text">发布后所有人可见,确定继续吗?</text>
      <view class="popover-demo__actions">
        <cd-button size="small" @click="popoverVisible = false">取消</cd-button>
        <cd-button size="small" type="primary" @click="onPopoverOk">发布</cd-button>
      </view>
    </view>
  </cd-popover>
</view>

Props ​

属性类型默认值必填说明
contentString''—提示内容(也可用 content 插槽承载富文本)
placementString'top'—12 个方位:top / top-start / top-end / bottom / ... / right-end
maxWidthString | Number240—最大宽度,超出折行
arrowSizeNumber6——
disabledBooleanfalse——
shieldBooleantrue—移动端是否渲染「点击空白处收起」的透明盾
customClassString''——

Events ​

事件名说明
visible-change显示状态变化

Slots ​

插槽名作用域参数说明
default—默认插槽
content——

设计说明 ​

以下由源码注释自动抽取,随代码更新。

  • 交互随「有没有鼠标」分流,而不是随屏幕宽度: 有鼠标(PC) → hover 进出,带延迟避免划过路径上的误闪 无鼠标(移动)→ 长按唤出,点击空白处收起 定位交给 useFloating(两段式测量),面板用 position:fixed 直接渲染 在组件内 —— 不传送、不遮罩、不锁滚动,这是气泡与弹窗的本质区别。

关联 ​

cd-popover

MIT 许可发布 · 由 Codedog.tech 长期维护 · UI 作者 Penn.Gu · 图标衍生自 Feather 与 Lucide,已保留署名