Skip to content

Popconfirm 气泡确认框

点击某个元素会弹出一个气泡式的确认框。

基础用法

<template>
  <x-popconfirm title="Are you shure to delete this item?">
    <x-button>Delete</x-button>
  </x-popconfirm>
</template>

自定义弹出框内容

可以通过 props 来自定义 Popconfirm 中内容

<template>
  <x-popconfirm
    width="220"
    confirm-button-text="Delete"
    cancel-button-text="No,Thanks"
    icon="trash"
    icon-color="#626aef"
    title="Are you sure to delete this item?"
  >
    <x-button>Delete</x-button>
  </x-popconfirm>
</template>

按钮回调

可以通过 confirmcancel 两个事件的监听来获取点击按钮后的回调

<script setup lang="ts">
const confirm = () => console.log('confirm')
const cancel = () => console.log('cancel')
</script>

<template>
  <x-popconfirm
    width="220"
    confirm-button-text="Delete"
    cancel-button-text="No,Thanks"
    icon="trash"
    icon-color="#626aef"
    title="Are you sure to delete this item?"
    @confirm="confirm"
    @cancel="cancel"
  >
    <x-button>Delete</x-button>
  </x-popconfirm>
</template>

Popconfirm API

Props

NameDescriptionTypeDefault
title提示文字string--
confirm-button-text确认按钮文字stringYes
cancel-button-text取消按钮文字stringNo
confirm-button-type确认按钮类型stringprimary
cancel-button-type取消按钮类型string--
icon图标stringquestion-circle
icon-color图标颜色string#f90
hide-icon隐藏图标booleanfalse
hide-after触发关闭的延时(单位:毫秒)number200
width宽度string150px

Events

NameDescriptionType
confirm点击确认按钮时触发(event: MouseEvent) => void
cancel点击取消按钮时触发(event: MouseEvent) => void

Slots

NameDescription
default默认插槽, 用于触发 Popconfirm 显示的 HTML 元素
reference同上,(default 别名)