Skip to content

Popconfirm 气泡确认框

点击某个元素后弹出轻量二次确认框。适合删除 SOP 项目、移除配置项、撤销操作等影响范围较小但需要确认的操作。

展示位置

通过 placement 设置气泡确认框的位置。位置由方向和对齐方式组成,例如 top-startleftbottom-end

vue
<el-popconfirm title="确认执行顶部左对齐操作?" placement="top-start">
  <template #reference>
    <el-button>top-start</el-button>
  </template>
</el-popconfirm>

<el-popconfirm title="确认执行底部右对齐操作?" placement="bottom-end">
  <template #reference>
    <el-button>bottom-end</el-button>
  </template>
</el-popconfirm>

基础用法

Popconfirm 的属性与 Popover 类似。内容通过 title 设置,content 属性会被忽略。

vue
<el-popconfirm title="确认删除这个 SOP 项目?">
  <template #reference>
    <el-button type="danger">删除</el-button>
  </template>
</el-popconfirm>

<el-popconfirm title="确认撤销本次配置变更?" confirm-button-text="确认" cancel-button-text="取消">
  <template #reference>
    <el-button>撤销变更</el-button>
  </template>
</el-popconfirm>

自定义图标

通过 iconicon-color 可以替换默认图标和颜色;设置 hide-icon 可以隐藏图标。

vue
<script setup lang="ts">
import { InfoFilled } from '@element-plus/icons-vue'
</script>

<template>
  <el-popconfirm
    title="该操作会影响当前报价,确认继续?"
    :icon="InfoFilled"
    icon-color="#626aef"
  >
    <template #reference>
      <el-button type="primary">品牌图标</el-button>
    </template>
  </el-popconfirm>
</template>

自定义按钮

可以通过 confirm-button-textcancel-button-textconfirm-button-typecancel-button-type 调整按钮文案和类型。

vue
<el-popconfirm
  width="240"
  title="确认删除该报价项?删除后无法恢复。"
  confirm-button-text="删除"
  cancel-button-text="暂不删除"
  confirm-button-type="danger"
  cancel-button-type="info"
  @confirm="handleDelete"
  @cancel="handleCancel"
>
  <template #reference>
    <el-button type="danger" plain>删除报价项</el-button>
  </template>
</el-popconfirm>

自定义操作区

actions 插槽可以完全自定义底部操作区。插槽提供 confirmcancel 方法,调用后会触发对应事件。

vue
<el-popconfirm title="是否确认删除该 SOP 步骤?" @confirm="handleDelete">
  <template #reference>
    <el-button>自定义操作区</el-button>
  </template>
  <template #actions="{ confirm, cancel }">
    <el-button size="small" @click="cancel">先保留</el-button>
    <el-button size="small" type="danger" @click="confirm">确认删除</el-button>
  </template>
</el-popconfirm>

确认与取消事件

通过 confirmcancel 事件处理用户选择。常见做法是在确认后执行删除、归档等操作,并用 Message 提示结果。

最近操作:暂无
vue
<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const lastAction = ref('暂无')

const handleDelete = () => {
  lastAction.value = '已确认'
  ElMessage.success('删除成功')
}

const handleCancel = () => {
  lastAction.value = '已取消'
  ElMessage.info('已取消操作')
}
</script>

主题与宽度

effect 可以设置 Tooltip 主题,width 控制气泡宽度,teleported 控制弹层是否插入到 body。

vue
<el-popconfirm title="浅色主题适合常规操作确认。" effect="light" width="220">
  <template #reference>
    <el-button>Light</el-button>
  </template>
</el-popconfirm>

<el-popconfirm title="深色主题适合局部深色工具栏。" effect="dark" width="220">
  <template #reference>
    <el-button>Dark</el-button>
  </template>
</el-popconfirm>

Popconfirm API

Popconfirm 继承 Tooltip 的大部分属性,但不包括 popper-classpopper-stylefallback-placements。重复属性可参考 Popover / Tooltip 文档。

Popconfirm 属性

属性名说明类型默认值
title标题内容string-
effectTooltip 主题,内置 darklightdark | light | stringlight
confirm-button-text确认按钮文字string-
cancel-button-text取消按钮文字string-
confirm-button-type确认按钮类型primary | success | warning | danger | info | textprimary
cancel-button-type取消按钮类型primary | success | warning | danger | info | texttext
icon自定义图标string | componentQuestionFilled
icon-color图标颜色string#f90
hide-icon是否隐藏图标booleanfalse
hide-after关闭时的延迟,单位毫秒number200
teleported是否将弹层插入至 bodybooleantrue
persistent长时间不触发且为 false 时是否删除弹层booleanfalse
width弹层宽度,最小宽度 150pxstring | number150
placement弹层出现位置enumbottom
trigger触发方式hover | click | focus | contextmenu / arrayclick
disabled是否禁用booleanfalse
offset弹层偏移量number12
show-arrow是否显示箭头booleantrue

Popconfirm 事件

事件名说明类型
confirm点击确认按钮时触发Function
cancel点击取消按钮时触发Function

Popconfirm 插槽

插槽名说明类型
reference触发 Popconfirm 显示的元素-
actions自定义页脚内容,提供 confirmcancel 方法object

Popconfirm 暴露

名称说明类型
popperRefel-popper 组件实例object
hide隐藏 PopconfirmFunction

HOMEVISTA 设计规范