Popover 弹出信息
弹出一些信息。
基础用法
<template>
<tu-space>
<tu-popover content="死亡不是失去了生命,而是走出了时间">
<template #trigger><tu-button>悬浮</tu-button></template>
</tu-popover>
<tu-popover content="死亡不是失去了生命,而是走出了时间" trigger="click">
<template #trigger><tu-button>点击</tu-button></template>
</tu-popover>
<tu-popover content="死亡不是失去了生命,而是走出了时间" trigger="focus">
<template #trigger><tu-button>聚焦</tu-button></template>
</tu-popover>
<tu-popover :visible="visible" content="死亡不是失去了生命,而是走出了时间" trigger="manual">
<template #trigger><tu-button @click="visible = !visible">手动</tu-button></template>
</tu-popover>
</tu-space>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const visible = ref(false)
</script>
展开源码
不要箭头
<template>
<tu-popover content="你的时间有限,所以不要为别人而活" hide-arrow>
<template #trigger>
<tu-button>不要箭头</tu-button>
</template>
</tu-popover>
</template>
展开源码
位置
有十二个不同的弹出方向
<template>
<div class="popover-placement-demo">
<div class="placement-top">
<tu-popover placement="top-start" trigger="click">
<template #trigger><tu-button>Top Start</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover trigger="click">
<template #trigger><tu-button>Top</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="top-end" trigger="click">
<template #trigger><tu-button>Top End</tu-button></template>
<div class="text">哦</div>
</tu-popover>
</div>
<div class="placement-left">
<tu-popover placement="left-start" trigger="click">
<template #trigger><tu-button>Left Start</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="left" trigger="click">
<template #trigger><tu-button>Left</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="left-end" trigger="click">
<template #trigger><tu-button>Left End</tu-button></template>
<div class="text">哦</div>
</tu-popover>
</div>
<div class="placement-right">
<tu-popover placement="right-start" trigger="click">
<template #trigger><tu-button>Right Start</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="right" trigger="click">
<template #trigger><tu-button>Right</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="right-end" trigger="click">
<template #trigger><tu-button>Right End</tu-button></template>
<div class="text">哦</div>
</tu-popover>
</div>
<div class="placement-bottom">
<tu-popover placement="bottom-start" trigger="click">
<template #trigger><tu-button>Bottom Start</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="bottom" trigger="click">
<template #trigger><tu-button>Bottom</tu-button></template>
<div class="text">哦</div>
</tu-popover>
<tu-popover placement="bottom-end" trigger="click">
<template #trigger><tu-button>Bottom End</tu-button></template>
<div class="text">哦</div>
</tu-popover>
</div>
</div>
</template>
<script setup lang="ts">
const content = '死亡不是失去了生命\n而是走出了时间'
</script>
<style lang="stylus">
$row-gap = 16px
$column-gap = 16px
.popover__placement {
.tu-button {
width: 100px;
}
.popover-placement-demo {
width: 532px;
display: flex;
flex-wrap: wrap;
}
.placement-top {
width: 432px;
margin-left: 100px;
display: flex;
gap: $row-gap;
}
.placement-left {
padding-top: $column-gap;
display: flex;
flex-direction: column;
gap: $column-gap;
}
.placement-right {
padding-top: $column-gap;
display: flex;
flex-direction: column;
gap: $column-gap;
margin-left: 332px;
}
.placement-bottom {
padding-top: $column-gap;
display: flex;
margin-left: 100px;
gap: $row-gap;
}
}
.tu-popover {
.text {
width: 96px;
height: 96px;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
line-height: 1;
font-size: 82px;
}
}
</style>
展开源码
自定义样式
可以使用 tu-popup
组件封装一个自定义 Popover,所有 Popover 组件都是基于该组件
<template>
<tu-popup :visible="visible" popup-margin="6">
<template #trigger>
<tu-button @click="visible = !visible">点我</tu-button>
</template>
<div :style="`
width: 100px;
height: 100px;
padding: 8px;
border-radius: 5px;
border: 2px solid #000;
background-color: #f495bf;
`">
自定义内容
</div>
</tu-popup>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const visible = ref(false)
</script>
展开源码
Popover 属性
名称 | 说明 | 类型 | 默认值 |
---|---|---|---|
trigger | 触发方式 | 'hover' | 'click' | 'focus' | 'manual' | 'hover' |
visible | 是否显示 Popover | boolean | false |
placement | Popover 的弹出位置 | 'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-start' | 'bottom' | 'bottom-end' | 'left-start' | 'left' | 'left-end' | 'top' |
content | 展示的内容 | string | undefined |
popover-margin | Popover 与触发元素的距离 | string | number | 8 |
arrow-side-margin | 箭头一侧对齐时与一侧的距离 | string | number | 10 |
hide-arrow | 是否隐藏箭头 | boolean | false |
disabled | 是否禁用 Popover 弹出 | boolean | false |
Popover 插槽
名称 | 说明 | 参数 |
---|---|---|
default | Poopver 内容插槽,附带 close 关闭函数 | ({ close }) |
trigger | 触发元素插槽 | () |