Skip to content

Popconfirm 气泡确认框

点击某个元素弹出一个简单的气泡确认框

ts
import { createApp } from 'vue'
import { Popconfirm as ElPopconfirm } from '@szhn/dh-design-pc'

const app = createApp()
app.use(ElPopconfirm)

展示位置

Popconfirm 提供 9 种展示位置。

<script setup lang="ts">
import { Button as ElButton, Popconfirm as ElPopconfirm } from '@szhn/dh-design-pc'

</script>

<template>
  <div class="popconfirm-base-box">
    <div class="row center">
      <el-popconfirm
        class="box-item"
        title="Top Left prompts info"
        placement="top-start"
      >
        <template #reference>
          <el-button>top-start</el-button>
        </template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Top Center prompts info"
        placement="top"
      >
        <template #reference>
          <el-button>top</el-button>
        </template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Top Right prompts info"
        placement="top-end"
      >
        <template #reference>
          <el-button>top-end</el-button>
        </template>
      </el-popconfirm>
    </div>
    <div class="row">
      <el-popconfirm
        class="box-item"
        title="Left Top prompts info"
        placement="left-start"
      >
        <template #reference>
          <el-button>left-start</el-button>
        </template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Right Top prompts info"
        placement="right-start"
      >
        <template #reference>
          <el-button>right-start</el-button>
        </template>
      </el-popconfirm>
    </div>
    <div class="row">
      <el-popconfirm
        class="box-item"
        title="Left Center prompts info"
        placement="left"
      >
        <template #reference>
          <el-button class="mt-3 mb-3">left</el-button>
        </template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Right Center prompts info"
        placement="right"
      >
        <template #reference>
          <el-button>right</el-button>
        </template>
      </el-popconfirm>
    </div>
    <div class="row">
      <el-popconfirm
        class="box-item"
        title="Left Bottom prompts info"
        placement="left-end"
      >
        <template #reference>
          <el-button>left-end</el-button>
        </template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Right Bottom prompts info"
        placement="right-end"
      >
        <template #reference>
          <el-button>right-end</el-button>
        </template>
      </el-popconfirm>
    </div>
    <div class="row center">
      <el-popconfirm
        class="box-item"
        title="Bottom Left prompts info"
        placement="bottom-start"
      >
        <template #reference> <el-button>bottom-start</el-button></template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Bottom Center prompts info"
        placement="bottom"
      >
        <template #reference> <el-button>bottom</el-button></template>
      </el-popconfirm>
      <el-popconfirm
        class="box-item"
        title="Bottom Right prompts info"
        placement="bottom-end"
      >
        <template #reference>
          <el-button>bottom-end</el-button>
        </template>
      </el-popconfirm>
    </div>
  </div>
</template>

<style>
.popconfirm-base-box {
  width: 600px;
}

.popconfirm-base-box .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.popconfirm-base-box .center {
  justify-content: center;
}

.popconfirm-base-box .box-item {
  width: 110px;
  margin-top: 10px;
}
</style>

基础用法

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

<script setup lang="ts">
import { Button as ElButton, Popconfirm as ElPopconfirm } from '@szhn/dh-design-pc'

</script>

<template>
  <el-popconfirm title="Are you sure to delete this?">
    <template #reference>
      <el-button>Delete</el-button>
    </template>
  </el-popconfirm>
</template>

自定义弹出框的内容

可以在 Popconfirm 中自定义内容。

<template>
  <el-popconfirm
    width="220"
    :icon="InfoFilled"
    icon-color="#626AEF"
    title="Are you sure to delete this?"
    @cancel="onCancel"
  >
    <template #reference>
      <el-button>Delete</el-button>
    </template>
    <template #actions="{ confirm, cancel }">
      <el-button size="small" @click="cancel">No!</el-button>
      <el-button
        type="danger"
        size="small"
        :disabled="!clicked"
        @click="confirm"
      >
        Yes?
      </el-button>
    </template>
  </el-popconfirm>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { InfoFilled } from '@szhn/dh-design-pc/icons'
import { Button as ElButton, Popconfirm as ElPopconfirm } from '@szhn/dh-design-pc'


const clicked = ref(false)
function onCancel() {
  clicked.value = true
}
</script>

多种让 Popconfirm 出现的方法

点击按钮触发事件

<template>
  <el-popconfirm
    confirm-button-text="Yes"
    cancel-button-text="No"
    :icon="InfoFilled"
    icon-color="#626AEF"
    title="Are you sure to delete this?"
    @confirm="confirmEvent"
    @cancel="cancelEvent"
  >
    <template #reference>
      <el-button>Delete</el-button>
    </template>
  </el-popconfirm>
</template>

<script setup lang="ts">
import { InfoFilled } from '@szhn/dh-design-pc/icons'
import { Button as ElButton, Popconfirm as ElPopconfirm } from '@szhn/dh-design-pc'


const confirmEvent = () => {
  console.log('confirm!')
}
const cancelEvent = () => {
  console.log('cancel!')
}
</script>

API

Attributes

属性名说明类型默认
title标题string
effect 2.11.2Tooltip 主题,内置了 dark / light 两种enum / stringlight
confirm-button-text确认按钮文字string
cancel-button-text取消按钮文字string
confirm-button-type确认按钮类型enumprimary
cancel-button-type取消按钮类型enumtext
icon自定义图标string / ComponentQuestionFilled
icon-colorIcon 颜色string#f90
hide-icon是否隐藏 Iconbooleanfalse
hide-after关闭时的延迟number200
teleported是否将 popover 的下拉列表插入至 body 元素booleantrue
persistent当 popover 组件长时间不触发且 persistent 属性设置为 false 时, popover 将会被删除booleanfalse
width弹层宽度,最小宽度 150pxstring / number150
tooltip继承自 Tooltip 的所有属性,但不包括:popper-classpopper-stylefallback-placements

Events

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

Slots

插槽名说明类型
reference触发 Popconfirm 显示的 HTML 元素
actions 2.8.1页脚的内容object

暴露

方法名详情Type
popperRef 2.10.7el-popper 组件实例object
hide 2.10.7hide popconfirmFunction