Popover 组件,可以认为是一个浮层卡片组件,相较于 Tooltip 组件,Popover 可以承载更复杂的内容,它的浮层内容区域被大致分为了 title 和 content 两大块,结构性更加明显。其中 content 部分可以收纳更复杂的交互,内容可以是按钮或一些高级组件。
基本展示
展开查看代码
vue
<template>
<j-popover placement="right" title="我是卡片标题">
<j-button>鼠标放在这里</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</template>
<template>
<j-popover placement="right" title="我是卡片标题">
<j-button>鼠标放在这里</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</template>
调整位置
使用placement
属性指定气泡卡片显示的位置。
展开查看代码
vue
<template>
<div style="width: 460px; max-width: 100%; margin: 50px auto 60px">
<j-space style="width: 100%; margin-top: 20px; justify-content: center">
<j-popover placement="top-start" title="Top Start">
<j-button>Top Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="top" title="Top">
<j-button>Top</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="top-end" title="Top End">
<j-button>Top End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
<j-popover placement="left-start" title="Left Start">
<j-button>Left Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="right-start" title="Right Start">
<j-button>Right Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
<j-popover placement="left" title="Left">
<j-button>Left</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="right" title="Right">
<j-button>Right</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
<j-popover placement="left-end" title="Left End">
<j-button>Left End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="right-end" title="Right End">
<j-button>Right End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: center">
<j-popover placement="bottom-start" title="Bottom Start">
<j-button>Bottom Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="bottom" title="Bottom">
<j-button>Bottom</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="bottom-end" title="Bottom End">
<j-button>Bottom End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
</div>
</template>
<template>
<div style="width: 460px; max-width: 100%; margin: 50px auto 60px">
<j-space style="width: 100%; margin-top: 20px; justify-content: center">
<j-popover placement="top-start" title="Top Start">
<j-button>Top Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="top" title="Top">
<j-button>Top</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="top-end" title="Top End">
<j-button>Top End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
<j-popover placement="left-start" title="Left Start">
<j-button>Left Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="right-start" title="Right Start">
<j-button>Right Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
<j-popover placement="left" title="Left">
<j-button>Left</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="right" title="Right">
<j-button>Right</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
<j-popover placement="left-end" title="Left End">
<j-button>Left End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="right-end" title="Right End">
<j-button>Right End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
<j-space style="width: 100%; margin-top: 20px; justify-content: center">
<j-popover placement="bottom-start" title="Bottom Start">
<j-button>Bottom Start</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="bottom" title="Bottom">
<j-button>Bottom</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
<j-popover placement="bottom-end" title="Bottom End">
<j-button>Bottom End</j-button>
<template #content>
<div>Content 1</div>
<div>Content 2</div>
</template>
</j-popover>
</j-space>
</div>
</template>
浮层内关闭
浮层内部也可以操作open
属性,实现关闭浮层的效果。
展开查看代码
vue
<template>
<j-popover placement="right" title="我是标题" v-model:open="open">
<j-button>Hover</j-button>
<template #content>
<div>我是内容</div>
<j-button size="small" style="margin-top: 10px" @click="onClickClose">点我关闭</j-button>
</template>
</j-popover>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const open = ref(false)
const onClickClose = () => {
open.value = false
}
</script>
<template>
<j-popover placement="right" title="我是标题" v-model:open="open">
<j-button>Hover</j-button>
<template #content>
<div>我是内容</div>
<j-button size="small" style="margin-top: 10px" @click="onClickClose">点我关闭</j-button>
</template>
</j-popover>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const open = ref(false)
const onClickClose = () => {
open.value = false
}
</script>
属性
参数 | 说明 | 类型 | 默认值 | 必填 |
---|---|---|---|---|
title | 气泡卡片的标题,支持字符串/属性/插槽 | string | VNode | 无 | 否 |
disabled | 禁止弹出浮层 | boolean | 无 | 否 |
content | 气泡卡片的内容,支持字符串/属性/插槽 | string | VNode | 无 | 否 |
placement | 浮层位置,可选top , bottom , left , right , top-start , top-end , bottom-start , bottom-end , left-start , left-end , right-start , right-end | Placement | 'bottom' | 否 |
open | 控制浮层显隐,支持 v-model,仅在必要时使用 open | boolean | undefined | 否 |
getPopupContainer | 指定浮层的容器,默认渲染到 body 下;如需渲染到父级元素下,可返回 null | () => null | HTMLElement | () => document.body | 否 |
destroyWhenHide | 控制隐藏后是否销毁浮层 | boolean | 无 | 否 |
mouseEnterDelay | 鼠标移入后延时多少才显示 Tooltip,单位:秒 | number | 0.1 | 否 |
mouseLeaveDelay | 鼠标移出后延时多少才隐藏 Tooltip,单位:秒 | number | 0.1 | 否 |
overlayClassName | 浮层class | string | 无 | 否 |
overlayStyle | 浮层style | CSSProperties | 无 | 否 |
overlayInnerStyle | 浮层内容区style | CSSProperties | 无 | 否 |
overlayColor | 浮层背景颜色 | string | 无 | 否 |
trigger | 触发方式 | "click" | "hover" | 'hover' | 否 |
arrowVisible | 是否显示箭头 | boolean | true | 否 |
offsetOption | offset 配置 | OffsetOptions | 12 | 否 |