使用用例
mode 和 placement
top hover (default)
bottom click
B 总是居中显示
syncWidth
默认
宽度同步
floating
默认
关闭跟随鼠标
autoPlacement 和 priority
调整浏览器窗口,移动非实时
关闭智能移动
slot数据
slot
expose
expose
expose
类型定义
type acceptDirection =
| 'top'| 'bottom'| 'left' | 'right'
| 'A' | 'C' | 'E' | 'G'
| 'BA' | 'B' | 'BC'
| 'DC' | 'D' | 'DE'
| 'FE' | 'F' | 'FG'
| 'HG' | 'H' | 'HA'
/**
*
* I 为触发元素
*
* top = ABC
* bottom = GFE
* left = AHG
* right = CDE
*
* A | B | C
* H | I | D
* G | F | E
*/
defineProps<{
mode?: 'hover' | 'click' | 'none'
placement?: acceptDirection
syncWidth?: boolean
autoPlacement?: boolean
priority?: acceptDirection[]
floating?: (content: number, popover: number) => boolean
}>()
defineExpose<{
popover: ref<HTMLElement>,
activeArea: ref<HTMLElement>,
popoverVisible: (v: boolean) => void,
visible: () => boolean
}>()
类型说明
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| mode | 触发方式,不为none时,内部自动控制 | string | hover click none | hover |
| placement | 弹出位置 | acceptDirection | 见类型定义 | top |
| syncWidth | 弹窗宽度同步触发区域 | boolean | false | |
| autoPlacement | 空间不足自动调整位置 | boolean | true | |
| priority | 弹出位置优先级 | acceptDirection[] | 见类型定义 | ['top', 'bottom', 'left', 'right'] |
| floating | 浮动阈值 | (c: number, p: number) => boolean | (c, p) => c > 3 * p |
插槽说明
| 插槽名 | 说明 | 暴露数据 | 数据说明 |
|---|---|---|---|
| default | 触发元素 | ||
| popover | 浮动元素 | {placement, visible, left, top, width, height } | 暴露了浮动元素实际大小及位置信息, 可以用于调整UI,如气泡尖 |
暴露接口
| 接口名 | 说明 | 类型 |
|---|---|---|
| popover | 浮动元素ref对象 | Ref<HTMLElement> |
| activeArea | 触发元素ref对象 | Ref<HTMLElement> |
| popoverVisible | 控制浮动元素是否显示 | (v: boolean) => void |
| visible | 浮动元素可视情况 | () => boolean |