最近搜索

vue3 Popconfirm 气泡确认框

浏览:13
管理员 2024-11-09 02:18

image.png

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



image.png

<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>
import { ref } from 'vue'
import { InfoFilled } from '@element-plus/icons-vue'

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




image.png

<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>
import { InfoFilled } from '@element-plus/icons-vue'

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





API

Attributes

属性名说明类型默认
title标题string
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

Events

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

Slots

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

源代码


联系站长

站长微信:xiaomao0055

站长QQ:14496453