Vue+ElementUI操作确认框及提示框的使用

在进行数据增删改查操作中为保证用户的使用体验,通常需要显示相关操作的确认信息以及操作结果的通知信息。文章以数据的下载和删除提示为例进行了简要实现,点击下载以及删除按钮,会出现对相关信息的提示,操作结果如下所示。

点击删除按钮,将会显示以下提示框。

点击取消按钮,提示已取消删除。

点击确定按钮,若删除成功则提示如下,删除失败则同理。

通过$this.confirm弹出操作提示界面,实现操作的确认。

通过$this.message弹出状态提示界面,提示操作是否成功。

界面代码如下所示:

html 复制代码
<el-table-column label="操作">
	<template slot-scope="scope">
		<el-button type="primary" round @click="downloadDataset">
			<i class="el-icon-edit"></i>下载
		</el-button>
		<el-button type="success" round>
			<i class="el-icon-edit"></i>编辑
		</el-button>
		<el-button type="danger" @click="deleteDatasetById(scope.row)" round>
			<i class="el-icon-document-delete"></i>删除
		</el-button>
	</template>
</el-table-column>

script代码如下所示:

javascript 复制代码
<script>
export default {
	//删除数据集
    deleteDatasetById(param) {
      let id = param.id //当前行对应数据的id
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.deleteDatasetById(id).then(res => {
          if (res.code === 20021) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getDatasets()
          } else {
            this.$message({
              type: 'error',
              message: '删除失败,请重试!'
            });
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    // 下载数据集
    downloadDataset() {
      this.$confirm('即将进行当前数据集的下载操作,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '下载成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消下载'
        });
      })
    },
}
<script>
相关推荐
yngsqq10 分钟前
窗体快速取消
java·开发语言
阿萨德528号12 分钟前
npm 包发布实战指南:从零发布、更新迭代到版本治理
前端·npm·策略模式
岁月如歌778615 分钟前
一次讲透 Redis 缓存击穿、穿透、雪崩,从原理到实战解决方案
java·后端·架构
IT_陈寒25 分钟前
Vue的v-for为啥把我的渲染顺序搞乱套了?
前端·人工智能·后端
sir.山1 小时前
在 Vue 3 项目中使用 Mock 数据
前端·vue.js·vue3·vite
AI多Agent协作实战派1 小时前
AI多Agent协作系统实战(四十六):改了十次规则,AI员工还是老样子——会话缓存的坑
java·spring·缓存
李剑一1 小时前
华为新上Pura X View阔直板手机,特殊屏幕比例设备下,前端应该怎么去适配更完美?送你一套完整工具代码
前端
新中地GIS开发老师1 小时前
WebGIS开发学生作品 | 基于无人机影像的烟草检测智能体与数字化管理平台
vue·web·mapbox·webgis
一知半解仙1 小时前
当机器人学会泛化,而我在写Java:一名后端开发者的2026年8月21日观察手记
java·开发语言·机器人
0xBADCODE1 小时前
Flask SSTI读SECRET_KEY+伪造Session:税务系统渗透全流程
前端·后端·python·安全·web安全·网络安全·flask