一、概述
在執行刪除操作時,我們一般會添加一個刪除確認框,當用戶點擊確認刪除后在執行刪除操作,這樣能提升用用戶體驗,
那么該如何快速實現呢?element中提供了相應的確認框,在官方文檔中不太好找,其實在message box彈框中,
有一個確認消息
二、代碼實現
test.vue

<template> <div style="width: 100%"> <el-button type="text" @click="open">點擊打開 Message Box</el-button> </div> </template> <script> export default { data() { return { } }, methods: { open() { this.$confirm('此操作將永久刪除該文件, 是否繼續?', '提示', { confirmButtonText: '確定', cancelButtonText: '取消', type: 'warning', center: true }).then(() => { this.$message({ type: 'success', message: '刪除成功!' }); }).catch(() => { this.$message({ type: 'info', message: '已取消刪除' }); }); } } } </script> <style> </style>
訪問頁面,效果如下:
本文參考鏈接:
https://element.eleme.io/#/zh-CN/component/message-box