Skip to content

Popconfirm 气泡确认框

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

基础用法

<script setup lang="ts">
import { ja, ko, en, zhCn, zhTw, EcConfigProvider } from "easy-collective-ui";
import { get } from "lodash-es";

import { computed, ref } from "vue";

const language = ref("");
const langMap = {
    ja,
    ko,
    en,
    zhCn,
    zhTw,
} as const;
const locale = computed(() => get(langMap, language.value));
const changelang = () => {
    const l = ["zhCn", "zhTw", "ko", "en", "ja"];
    language.value = l[(l.indexOf(language.value) + 1) % l.length];
};
</script>
<template>
    <ec-button @click="changelang" type="info" style="margin-right: 20px">change language</ec-button>
    <ec-config-provider :locale="locale">
        <ec-popconfirm title="Are you shure to delete this item?">
            <ec-button>Delete</ec-button>
        </ec-popconfirm>
    </ec-config-provider>
</template>

自定义弹出框内容

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

<template>
    <ec-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?">
        <ec-button>Delete</ec-button>
    </ec-popconfirm>
</template>

按钮回调

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

<template>
    <ec-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="$message.success('Delete Success')"
        @cancel="$message.info('Cancel')"
    >
        <ec-button>Delete</ec-button>
    </ec-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 别名)