Skip to content

Popper 弹出信息

在内容周围弹出一些隐藏的信息。内置样式,需要自行定制。 如果你只想展示一些基本的文本内容,推荐使用 Tooltip

组件注册

js
import { FPopper } from '@fesjs/fes-design';

app.use(FPopper);

代码演示

基础用法

属性 trigger 设置触发方式,hoverclickfocus

play
<template>
    <FPopper placement="bottom" trigger="hover" :arrow="true">
        <template #trigger>
            <FButton>Hover to activate</FButton>
        </template>
        <div style="padding: 30px">this is content, this is content, this is content</div>
    </FPopper>
    <FPopper placement="top" trigger="click" :arrow="true">
        <template #trigger>
            <FButton style="margin-left: 10px">Click to activate</FButton>
        </template>
        <div style="padding: 30px">this is content, this is content, this is content</div>
    </FPopper>
    <FPopper placement="right" trigger="focus" :arrow="true">
        <template #trigger>
            <FButton style="margin-left: 10px">Focus to activate</FButton>
        </template>
        <div style="padding: 30px">this is content, this is content, this is content</div>
    </FPopper>
</template>

<script setup lang="ts"></script>

<style scoped></style>

是否显示

play
<template>
    <FSpace>
        <FForm :labelWidth="100">
            <FFormItem label="是否显示:">
                <FRadioGroup
                    v-model="visible"
                    :cancelable="false"
                    :options="[
                        { label: '否(默认)', value: false },
                        { label: '', value: true },
                    ]"
                />
            </FFormItem>
        </FForm>
    </FSpace>

    <FDivider />

    <FPopper v-model="visible" placement="bottom" trigger="click" :arrow="true" :popperStyle="{ zIndex: 1500 }">
        <template #trigger>
            <FButton>Click to activate</FButton>
        </template>
        <div style="padding: 30px">this is content, this is content, this is content</div>
    </FPopper>
</template>

<script setup>
import { ref } from 'vue';

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

<style scoped></style>

受控模式

play
<template>
    <FSpace>
        <FForm :labelWidth="150">
            <FFormItem label="是否显示:">
                <FRadioGroup
                    v-model="visible"
                    :cancelable="false"
                    :options="[
                        { label: '否(默认)', value: false },
                        { label: '', value: true },
                    ]"
                />
            </FFormItem>
            <FFormItem label="点击空白处是否关闭:">
                <FRadioGroup
                    v-model="closeOnClickOutside"
                    :cancelable="false"
                    :options="[
                        { label: '否(默认)', value: false },
                        { label: '', value: true },
                    ]"
                />
            </FFormItem>
        </FForm>
    </FSpace>

    <FDivider />

    <FSpace>
        <FPopper
            :modelValue="visible"
            placement="bottom"
            trigger="click"
            :arrow="true"
            :passive="false"
            @clickOutside="handleClickOutside"
        >
            <template #trigger>
                <FButton @click="visible = true">Click to activate</FButton>
            </template>
            <div style="padding: 30px">this is content, this is content, this is content</div>
        </FPopper>
    </FSpace>
</template>

<script setup>
import { ref } from 'vue';

const visible = ref(false);
const closeOnClickOutside = ref(true);

function handleClickOutside() {
    console.log('[tooltip.passive] clickOutside');
    if (closeOnClickOutside.value) {
        visible.value = false;
    }
}
</script>

Popper Props

属性说明类型默认值
v-model手动控制显示booleanfalse
placement出现的位置,可选值有top top-start top-end bottom bottom-start bottom-end right right-start right-end left left-start left-endstringauto
trigger触发类型hover click focus, confirm 模式下只能是clickstringhover
disabled是否可用booleanfalse
offset出现位置的偏移量number6
arrow是否显示箭头booleantrue
appendToContainer弹窗内容是否添加到指定的 DOM 元素booleantrue
popperClass弹出框的样式类名string | object | Array-
popperStyle弹出框的样式object-
showAfter显示的延迟时间number0
passive是否受控模式,true-非受控,false-受控booleantrue
hideAfter隐藏的延迟时间number0
lazy是否懒渲染booleantrue
getContainer配置渲染节点的输出位置() => HTMLElement() => document.body

Popper Events

事件名称说明回调参数
clickOutside是否点击了外部区域() => void

Popper Methods

方法名称说明参数
updatePopperPosition更新弹出层位置() => void

Popper Slots

名称说明
trigger触发提示包裹的内容
default提示内容