Skip to content

Tooltip 文字提示

文字提示,在鼠标 hover 时显示提示文字。

TIP

todo: 目前只是做了简单封装,待完善(effect 部分)

基础用法

<template>
  <div class="tooltip-base-box">
    <div class="row center">
      <er-tooltip
        class="box-item"
        content="Top Left prompts info"
        placement="top-start"
      >
        <er-button>top-start</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Top Center prompts info"
        placement="top"
      >
        <er-button>top</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Top Right prompts info"
        placement="top-end"
      >
        <er-button>top-end</er-button>
      </er-tooltip>
    </div>
    <div class="row">
      <er-tooltip
        class="box-item"
        content="Left Top prompts info"
        placement="left-start"
      >
        <er-button>left-start</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Right Top prompts info"
        placement="right-start"
      >
        <er-button>right-start</er-button>
      </er-tooltip>
    </div>
    <div class="row">
      <er-tooltip
        class="box-item"
        content="Left Center prompts info"
        placement="left"
      >
        <er-button class="mt-3 mb-3">left</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Right Center prompts info"
        placement="right"
      >
        <er-button>right</er-button>
      </er-tooltip>
    </div>
    <div class="row">
      <er-tooltip
        class="box-item"
        content="Left Bottom prompts info"
        placement="left-end"
      >
        <er-button>left-end</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Right Bottom prompts info"
        placement="right-end"
      >
        <er-button>right-end</er-button>
      </er-tooltip>
    </div>
    <div class="row center">
      <er-tooltip
        class="box-item"
        content="Bottom Left prompts info"
        placement="bottom-start"
      >
        <er-button>bottom-start</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Bottom Center prompts info"
        placement="bottom"
      >
        <er-button>bottom</er-button>
      </er-tooltip>
      <er-tooltip
        class="box-item"
        content="Bottom Right prompts info"
        placement="bottom-end"
      >
        <er-button>bottom-end</er-button>
      </er-tooltip>
    </div>
  </div>
</template>

<style>
.tooltip-base-box {
  width: 600px;
}
.tooltip-base-box .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tooltip-base-box .center {
  justify-content: center;
}
.tooltip-base-box .box-item {
  width: 110px;
  margin-top: 10px;
}
</style>

更多内容的文字提示

展示多行文本或者设置内容的格式 通过 content 插槽设置内容

<template>
  <er-tooltip placement="top">
    <template #content> multiple lines<br />second line </template>
    <er-button>Top center</er-button>
  </er-tooltip>
</template>

禁用状态

禁用状态,鼠标悬停无法触发文字提示。disabled 属性可以满足这个需求。

<script lang="ts" setup>
import { ref } from "vue";

const disabled = ref(false);
</script>

<template>
  <er-tooltip
    :disabled="disabled"
    content="click to close tooltip function"
    placement="bottom"
  >
    <er-button @click="disabled = !disabled"
      >click to {{ disabled ? "active" : "close" }} tooltip function</er-button
    >
  </er-tooltip>
</template>

Tooltip API

Props

NameDescriptionTypeDefault
content提示文字string-
disabled是否禁用booleanfalse
placement弹出位置stringbottom
trigger触发方式stringhover
manual手动控制booleanfalse
popper-optionspopper 配置object 参考popper.js{}
transition动画stringfade
show-timeout显示延时number0
hide-timeout隐藏延时number200

Events

NameDescriptionType
visible-change显示隐藏状态改变时触发(visible: boolean) => void
click-outside点击外部时触发() => void

Slots

NameDescription
default默认插槽
content内容插槽

Expose

NameDescriptionType
show显示() => void
hide隐藏() => void