Skip to content

Popconfirm 气泡确认框

点击元素,弹出气泡确认框。

基础用法

Popconfirm 的属性与 Popover 很类似,因此对于重复属性,请参考 Popover 的文档,在此文档中不做详尽解释。

vue
<template>
  <x-popconfirm title="确定删除吗?" @confirm="handleConfirm" @cancel="handleCancel">
    <x-button>删除</x-button>
  </x-popconfirm>
</template>

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

const result = ref('')

const handleConfirm = () => {
  result.value = '你点击了确定按钮'
}

const handleCancel = () => {
  result.value = '你点击了取消按钮'
}
</script>

自定义按钮

可以自定义按钮文字、类型等。

vue
<template>
  <x-popconfirm
    title="这是一段内容确定删除吗?"
    confirm-button-text="好的"
    cancel-button-text="不用了"
    confirm-button-type="danger"
    @confirm="handleDelete"
  >
    <x-button type="danger">删除</x-button>
  </x-popconfirm>
</template>

自定义弹出位置

支持 12 个弹出位置。

vue
<template>
  <x-popconfirm title="上" placement="top">
    <x-button>上</x-button>
  </x-popconfirm>
  <x-popconfirm title="下" placement="bottom">
    <x-button>下</x-button>
  </x-popconfirm>
  <x-popconfirm title="左" placement="left">
    <x-button>左</x-button>
  </x-popconfirm>
  <x-popconfirm title="右" placement="right">
    <x-button>右</x-button>
  </x-popconfirm>
</template>

隐藏图标

设置 hide-icon 可以隐藏图标。

vue
<template>
  <x-popconfirm title="确定删除吗?" :hide-icon="true">
    <x-button>隐藏图标</x-button>
  </x-popconfirm>
</template>

隐藏按钮

可以单独隐藏确认或取消按钮。

vue
<template>
  <x-popconfirm title="只有确定按钮" :hide-cancel-button="true">
    <x-button>隐藏取消按钮</x-button>
  </x-popconfirm>
  <x-popconfirm title="只有取消按钮" :hide-confirm-button="true">
    <x-button>隐藏确定按钮</x-button>
  </x-popconfirm>
</template>

API

Props

属性说明类型默认值
title标题string''
confirm-button-text确认按钮文字string'确定'
cancel-button-text取消按钮文字string'取消'
confirm-button-type确认按钮类型'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default''primary'
cancel-button-type取消按钮类型'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default''default'
icon图标string''
icon-color图标颜色string'#faad14'
hide-icon是否隐藏图标booleanfalse
hide-cancel-button是否隐藏取消按钮booleanfalse
hide-confirm-button是否隐藏确认按钮booleanfalse
disabled是否禁用booleanfalse
width宽度string | number200
placement弹出位置'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end' | 'right' | 'right-start' | 'right-end''top'
offset出现位置的偏移量number12
show-arrow是否显示箭头booleantrue

Events

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

Slots

插槽名说明
default触发 Popconfirm 显示的元素
title标题内容
icon图标内容

基于 MIT 许可发布