Skip to content

Popconfirm 用于弹出气泡式的确认框,可以在目标元素附近弹出,相较于 Modal 对话框有着更轻量的优势,相信你会爱上使用这个组件。

基本展示

展开查看代码
vue
<template>
    <j-popconfirm placement="right" title="你确认要删除它吗?" description="这是一段描述,你确认要删吗?">
        <j-button danger type="primary">删除</j-button>
    </j-popconfirm>
</template>
<template>
    <j-popconfirm placement="right" title="你确认要删除它吗?" description="这是一段描述,你确认要删吗?">
        <j-button danger type="primary">删除</j-button>
    </j-popconfirm>
</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-popconfirm placement="top-start" title="Top Start">
                <j-button>Top Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="top" title="Top">
                <j-button>Top</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="top-end" title="Top End">
                <j-button>Top End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
            <j-popconfirm placement="left-start" title="Left Start">
                <j-button>Left Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="right-start" title="Right Start">
                <j-button>Right Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
            <j-popconfirm placement="left" title="Left">
                <j-button>Left</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="right" title="Right">
                <j-button>Right</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
            <j-popconfirm placement="left-end" title="Left End">
                <j-button>Left End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="right-end" title="Right End">
                <j-button>Right End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: center">
            <j-popconfirm placement="bottom-start" title="Bottom Start">
                <j-button>Bottom Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="bottom" title="Bottom">
                <j-button>Bottom</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="bottom-end" title="Bottom End">
                <j-button>Bottom End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </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-popconfirm placement="top-start" title="Top Start">
                <j-button>Top Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="top" title="Top">
                <j-button>Top</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="top-end" title="Top End">
                <j-button>Top End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
            <j-popconfirm placement="left-start" title="Left Start">
                <j-button>Left Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="right-start" title="Right Start">
                <j-button>Right Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
            <j-popconfirm placement="left" title="Left">
                <j-button>Left</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="right" title="Right">
                <j-button>Right</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: space-between">
            <j-popconfirm placement="left-end" title="Left End">
                <j-button>Left End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="right-end" title="Right End">
                <j-button>Right End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
        <j-space style="width: 100%; margin-top: 20px; justify-content: center">
            <j-popconfirm placement="bottom-start" title="Bottom Start">
                <j-button>Bottom Start</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="bottom" title="Bottom">
                <j-button>Bottom</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
            <j-popconfirm placement="bottom-end" title="Bottom End">
                <j-button>Bottom End</j-button>

                <template #description>
                    <div>Content 1</div>
                    <div>Content 2</div>
                </template>
            </j-popconfirm>
        </j-space>
    </div>
</template>

异步确认

onConfirm支持异步,当它返回一个Promise时,确认按钮的loading状态会从onConfirm开始执行后一直持续,直到Promise状态确定后结束。这对于 ajax 类操作是非常友好的,因为你无需自行管理按钮的loading状态!

展开查看代码
vue
<template>
    <j-popconfirm title="你确认要删除它吗?" description="如果onConfirm返回Promise,可以支持异步确认哦!" @confirm="onConfirm">
        <j-button danger type="primary">删除</j-button>
    </j-popconfirm>
</template>

<script setup lang="ts">
import { sleep } from '@jview/utils'

const onConfirm = async () => {
    // 用一个 3 秒的延迟模拟 ajax 请求
    await sleep(3)
    return Promise.resolve(true)
}
</script>
<template>
    <j-popconfirm title="你确认要删除它吗?" description="如果onConfirm返回Promise,可以支持异步确认哦!" @confirm="onConfirm">
        <j-button danger type="primary">删除</j-button>
    </j-popconfirm>
</template>

<script setup lang="ts">
import { sleep } from '@jview/utils'

const onConfirm = async () => {
    // 用一个 3 秒的延迟模拟 ajax 请求
    await sleep(3)
    return Promise.resolve(true)
}
</script>

属性

参数说明类型默认值必填
disabled禁止弹出浮层boolean
title确认框的标题,支持字符串/属性/插槽string | VNode
description确认框的详细描述,支持字符串/属性/插槽string | VNode
placement浮层位置,可选top, bottom, left, right, top-start, top-end, bottom-start, bottom-end, left-start, left-end, right-start, right-endPlacement'bottom'
icon确认框标题左侧的图标,支持属性/插槽VNode
open控制浮层显隐,支持 v-model,仅在必要时使用 openbooleanundefined
onConfirm确认事件回调,如果返回 Promise,则可以支持异步确认效果Function
getPopupContainer指定浮层的容器,默认渲染到 body 下;如需渲染到父级元素下,可返回 null() => null | HTMLElement() => document.body
cancelButton自定义渲染取消按钮,支持属性或插槽VNode
destroyWhenHide控制隐藏后是否销毁浮层boolean
confirmButton自定义渲染确认按钮,支持属性或插槽VNode
mouseEnterDelay鼠标移入后延时多少才显示 Tooltip,单位:秒number0.1
cancelText取消按钮文字string'取消'
mouseLeaveDelay鼠标移出后延时多少才隐藏 Tooltip,单位:秒number0.1
confirmText确认按钮文字string'确定'
overlayClassName浮层classstring
titleIcon标题左侧图标VNode<ExclamationCircleFilled />
overlayStyle浮层styleCSSProperties
cancelButtonProps传给取消按钮的属性object
overlayInnerStyle浮层内容区styleCSSProperties
confirmButtonProps传给确认按钮的属性object
overlayColor浮层背景颜色string
showCancel是否显示取消按钮,默认显示booleantrue
trigger触发方式"click" | "hover"'hover'
arrowVisible是否显示箭头booleantrue
offsetOptionoffset 配置OffsetOptions12