程序员scholar 程序员scholar
首页
  • Java 基础

    • JavaSE
    • JavaIO
    • JavaAPI速查
  • Java 高级

    • JUC
    • JVM
    • Java新特性
    • 设计模式
  • Web 开发

    • Servlet
    • Java网络编程
  • Web 标准

    • HTML
    • CSS
    • JavaScript
  • 前端框架

    • Vue2
    • Vue3
    • Vue3 + TS
    • 微信小程序
    • uni-app
  • 工具与库

    • jQuery
    • Ajax
    • Axios
    • Webpack
    • Vuex
    • WebSocket
    • 第三方登录
  • 后端与语言扩展

    • ES6
    • Typescript
    • node.js
  • Element-UI
  • Apache ECharts
  • 数据结构
  • HTTP协议
  • HTTPS协议
  • 计算机网络
  • Linux常用命令
  • Windows常用命令
  • SQL数据库

    • MySQL
    • MySQL速查
  • NoSQL数据库

    • Redis
    • ElasticSearch
  • 数据库

    • MyBatis
    • MyBatis-Plus
  • 消息中间件

    • RabbitMQ
  • 服务器

    • Nginx
  • Spring框架

    • Spring6
    • SpringMVC
    • SpringBoot
    • SpringSecurity
  • SpringCould微服务

    • SpringCloud基础
    • 微服务之DDD架构思想
  • 日常必备

    • 开发常用工具包
    • Hutoll工具包
    • IDEA常用配置
    • 开发笔记
    • 日常记录
    • 项目部署
    • 网站导航
    • 产品学习
    • 英语学习
  • 代码管理

    • Maven
    • Git教程
    • Git小乌龟教程
  • 运维工具

    • Docker
    • Jenkins
    • Kubernetes
  • 算法笔记

    • 算法思想
    • 刷题笔记
  • 面试问题常见

    • 十大经典排序算法
    • 面试常见问题集锦
关于
GitHub (opens new window)
首页
  • Java 基础

    • JavaSE
    • JavaIO
    • JavaAPI速查
  • Java 高级

    • JUC
    • JVM
    • Java新特性
    • 设计模式
  • Web 开发

    • Servlet
    • Java网络编程
  • Web 标准

    • HTML
    • CSS
    • JavaScript
  • 前端框架

    • Vue2
    • Vue3
    • Vue3 + TS
    • 微信小程序
    • uni-app
  • 工具与库

    • jQuery
    • Ajax
    • Axios
    • Webpack
    • Vuex
    • WebSocket
    • 第三方登录
  • 后端与语言扩展

    • ES6
    • Typescript
    • node.js
  • Element-UI
  • Apache ECharts
  • 数据结构
  • HTTP协议
  • HTTPS协议
  • 计算机网络
  • Linux常用命令
  • Windows常用命令
  • SQL数据库

    • MySQL
    • MySQL速查
  • NoSQL数据库

    • Redis
    • ElasticSearch
  • 数据库

    • MyBatis
    • MyBatis-Plus
  • 消息中间件

    • RabbitMQ
  • 服务器

    • Nginx
  • Spring框架

    • Spring6
    • SpringMVC
    • SpringBoot
    • SpringSecurity
  • SpringCould微服务

    • SpringCloud基础
    • 微服务之DDD架构思想
  • 日常必备

    • 开发常用工具包
    • Hutoll工具包
    • IDEA常用配置
    • 开发笔记
    • 日常记录
    • 项目部署
    • 网站导航
    • 产品学习
    • 英语学习
  • 代码管理

    • Maven
    • Git教程
    • Git小乌龟教程
  • 运维工具

    • Docker
    • Jenkins
    • Kubernetes
  • 算法笔记

    • 算法思想
    • 刷题笔记
  • 面试问题常见

    • 十大经典排序算法
    • 面试常见问题集锦
关于
GitHub (opens new window)
npm

(进入注册为作者充电)

  • 快速入手

  • 基础组件

  • 表单组件

  • 数据展示组件

  • 反馈组件

  • 导航组件

  • 其他组件

    • 对话框组件 (Dialog)
    • 文字提示组件 (Tooltip)
    • 弹出框组件 (Popover)
    • 气泡确认框组件 (Popconfirm)
      • 1. 基本用法
        • Popconfirm 属性
        • Popconfirm 方法
        • Popconfirm 事件
        • Popconfirm 插槽
      • 2. 常用示例
        • 1. 基本使用
        • 2. 自定义按钮文本
        • 3. 自定义图标和隐藏图标
        • 4. 多个 Popconfirm 组合使用
    • 卡片组件 (Card)
    • 走马灯组件 (Carousel)
    • 折叠面板组件 (Collapse)
    • 时间线组件 (Timeline)
    • 分割线组件 (Divider)
    • 日历组件 (Calendar)
    • 图片组件 (Image)
    • 回到顶部组件 (Backtop)
    • 无限滚动 (InfiniteScroll)
    • 无限滚动 (vue-infinite-loading)
    • 抽屉组件 (Drawer)
  • Element-UI
  • 其他组件
scholar
2024-08-12
目录

气泡确认框组件 (Popconfirm)

# 气泡确认框组件 (Popconfirm)

Element-UI 的 Popconfirm 组件用于点击元素时弹出气泡确认框,用于在用户执行某些操作前进行二次确认,避免误操作。

提示

Popover 组件官方文档:https://element.eleme.cn/#/zh-CN/component/popover (opens new window)

# 1. 基本用法

基本语法:使用 <el-popconfirm> 标签创建一个气泡确认框,通过 title 属性设置确认框的标题。确认和取消按钮的文本可以通过 confirm-button-text 和 cancel-button-text 属性进行设置。

<template>
  <el-popconfirm
    title="确定要删除吗?"
    confirm-button-text="确定"
    cancel-button-text="取消"
    @confirm="handleConfirm"
    @cancel="handleCancel">
    <el-button slot="reference">删除</el-button>
  </el-popconfirm>
</template>

<script>
export default {
  methods: {
    handleConfirm() {
      this.$message.success('已确认');
    },
    handleCancel() {
      this.$message.info('已取消');
    }
  }
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  • 标题:通过 title 属性设置确认框的提示信息。
  • 确认和取消按钮:通过 confirm-button-text 和 cancel-button-text 属性自定义按钮文本。
  • 事件处理:可以使用 confirm 和 cancel 事件来处理用户点击确认或取消按钮的操作。
  • image-20240811153319472

# Popconfirm 属性

参数 说明 类型 可选值 默认值
title 标题 String — —
confirm-button-text 确认按钮文字 String — —
cancel-button-text 取消按钮文字 String — —
confirm-button-type 确认按钮类型 String — Primary
cancel-button-type 取消按钮类型 String — Text
icon Icon String — el-icon-question
icon-color Icon 颜色 String — #f90
hide-icon 是否隐藏 Icon Boolean — false

# Popconfirm 方法

Popconfirm 组件本身没有定义特定的方法,但可以使用 confirm 和 cancel 事件进行操作处理。

# Popconfirm 事件

事件名称 说明 回调参数
confirm 点击确认按钮时触发 —
cancel 点击取消按钮时触发 —

# Popconfirm 插槽

插槽名称 说明
reference 触发 Popconfirm 显示的 HTML 元素

# 2. 常用示例

# 1. 基本使用

展示一个带有默认配置的 Popconfirm 组件,用户点击删除按钮时会弹出确认框。

<template>
  <el-popconfirm
    title="确定要删除吗?"
    @confirm="handleConfirm"
    @cancel="handleCancel">
    <el-button slot="reference" type="danger">删除</el-button>
  </el-popconfirm>
</template>

<script>
export default {
  methods: {
    handleConfirm() {
      this.$message.success('已确认删除');
    },
    handleCancel() {
      this.$message.info('已取消操作');
    }
  }
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  • 基本操作:点击删除按钮后,会显示带有默认配置的 Popconfirm 气泡确认框,用户可以选择确认或取消。
  • image-20240811153440823

# 2. 自定义按钮文本

通过 confirm-button-text 和 cancel-button-text 自定义确认和取消按钮的文本内容。

<template>
  <el-popconfirm
    title="是否确认执行此操作?"
    confirm-button-text="好的"
    cancel-button-text="不用了"
    @confirm="handleConfirm"
    @cancel="handleCancel">
    <el-button slot="reference" type="primary">操作</el-button>
  </el-popconfirm>
</template>

<script>
export default {
  methods: {
    handleConfirm() {
      this.$message.success('操作已确认');
    },
    handleCancel() {
      this.$message.info('操作已取消');
    }
  }
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  • 自定义文本:自定义确认和取消按钮的文本,使其更符合实际使用场景的需求。
  • image-20240811160117875

# 3. 自定义图标和隐藏图标

通过 icon 和 icon-color 自定义气泡确认框的图标和颜色,或者通过 hide-icon 隐藏图标。

<template>
  <el-popconfirm
    title="确认删除吗?"
    icon="el-icon-warning"
    icon-color="red"
    confirm-button-text="确定"
    cancel-button-text="取消"
    @confirm="handleConfirm"
    @cancel="handleCancel">
    <el-button slot="reference" type="danger">删除</el-button>
  </el-popconfirm>

  <el-popconfirm
    title="确定继续吗?"
    :hide-icon="true"
    confirm-button-text="继续"
    cancel-button-text="取消"
    @confirm="handleConfirm"
    @cancel="handleCancel">
    <el-button slot="reference" type="warning">继续</el-button>
  </el-popconfirm>
</template>

<script>
export default {
  methods: {
    handleConfirm() {
      this.$message.success('操作已确认');
    },
    handleCancel() {
      this.$message.info('操作已取消');
    }
  }
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  • 自定义图标:通过 icon 和 icon-color 属性自定义确认框的图标和颜色,使其更具视觉提示性。
  • 隐藏图标:使用 hide-icon 属性可以隐藏确认框的图标,使其界面更简洁。
  • image-20240811160211385

# 4. 多个 Popconfirm 组合使用

在同一页面中可以同时使用多个 Popconfirm 组件,每个组件独立控制。

<template>
  <div>
    <el-popconfirm
      title="确定发布吗?"
      confirm-button-text="发布"
      cancel-button-text="取消"
      @confirm="handleConfirm"
      @cancel="handleCancel">
      <el-button slot="reference" type="primary">发布</el-button>
    </el-popconfirm>

    <el-popconfirm
      title="确定删除吗?"
      confirm-button-text="删除"
      cancel-button-text="取消"
      @confirm="handleConfirm"
      @cancel="handleCancel">
      <el-button slot="reference" type="danger">删除</el-button>
    </el-popconfirm>
  </div>
</template>

<script>
export default {
  methods: {
    handleConfirm() {
      this.$message.success('操作已确认');
    },
    handleCancel() {
      this.$message.info('操作已取消');
    }
  }
};
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  • 组合使用:多个 Popconfirm 组件可以在同一页面中组合使用,每个组件都有自己独立的确认和取消处理逻辑。
  • image-20240811160251151

总结

  • 简洁的用户确认界面:Popconfirm 提供了一个简洁的确认界面,可以有效防止用户误操作。
  • 灵活的自定义选项:通过多种属性配置,可以定制按钮文本、图标样式等,使确认框更符合场景需求。
  • 方便的事件处理:支持 confirm 和 cancel 事件,允许开发者在用户确认或取消操作时进行处理。
编辑此页 (opens new window)
上次更新: 2024/12/28, 18:32:08
弹出框组件 (Popover)
卡片组件 (Card)

← 弹出框组件 (Popover) 卡片组件 (Card)→

Theme by Vdoing | Copyright © 2019-2025 程序员scholar
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式