有没有办法添加ui-element、ElMessageBox确认按钮点击事件?
当我从表中删除数据时,我希望它首先在屏幕中间弹出一个警告。删除功能已准备就绪,我只想添加确认按钮单击事件(删除功能)当我弹出ElMessageBox时。当我按yes时,删除应该完成。但我找不到方法来做到这一点。有什么帮助吗?提前致谢!
这是我的 html 代码
<el-button class="menu-link px-3" type="text" @click="open">
<span class="svg-icon svg-icon-3">
<inline-svg src="media/icons/duotune/art/art005.svg" /> </span
> Delete
</el-button>
这是我的脚本代码
const open = () => {
ElMessageBox.confirm(
'Do you want to continue the deletion?',
{
confirmButtonText: 'Yes',
cancelButtonText: 'No',
type: 'warning',
center: true,
})
.then(() => {
ElMessage({
type: 'success',
message: 'Deletion completed',
})
})
.catch(() => {
ElMessage({
type: 'info',
message: 'Deletion canceled',
})
})
}
这是我的删除函数
const deleteCustomer = (id) => {
for (let i = 0; i < tableData.value.length; i++) {
if (tableData.value[i].id === id) {
tableData.value.splice(i, 1);
}
}
};
When I delete a data from the table, I want it to pop up a warning in the middle of the screen first.Delete function is ready,i just want to add confirm button click event(delete function) when i pop up ElMessageBox.When I press yes, the deletion should be done.But i couldn't find a way to do it.Any helps? Thanks in advance!
Here is my html code
<el-button class="menu-link px-3" type="text" @click="open">
<span class="svg-icon svg-icon-3">
<inline-svg src="media/icons/duotune/art/art005.svg" /> </span
> Delete
</el-button>
Here is my script code
const open = () => {
ElMessageBox.confirm(
'Do you want to continue the deletion?',
{
confirmButtonText: 'Yes',
cancelButtonText: 'No',
type: 'warning',
center: true,
})
.then(() => {
ElMessage({
type: 'success',
message: 'Deletion completed',
})
})
.catch(() => {
ElMessage({
type: 'info',
message: 'Deletion canceled',
})
})
}
Here is my Delete function
const deleteCustomer = (id) => {
for (let i = 0; i < tableData.value.length; i++) {
if (tableData.value[i].id === id) {
tableData.value.splice(i, 1);
}
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您单击 yes 时,open 函数的
.then()
部分将被执行。在该块中,您需要调用删除函数。您还需要将 id 传递给
open()
函数。就像open(id)
。this.deleteCustomer(id)
或只是deleteCustomer(id)
。When you click yes the
.then()
part of open function gets executed. In that block you need to call the delete function.You need to pass id to
open()
function as well. Likeopen(id)
.this.deleteCustomer(id)
or justdeleteCustomer(id)
.