首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有任何方法添加ui元素,ElMessageBox确认按钮单击事件?

是否有任何方法添加ui元素,ElMessageBox确认按钮单击事件?
EN

Stack Overflow用户
提问于 2022-03-21 13:25:24
回答 1查看 226关注 0票数 2

当我从表中删除a数据时,我希望它在屏幕中间弹出一个警告,first.Delete函数已经准备好了,我只想添加确认按钮单击事件(删除函数)当我弹出ElMessageBox.When时,我按下“是”,删除应该是done.But提前感谢!

这是我的html代码

代码语言:javascript
复制
              <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
            >&nbsp;Delete
          </el-button>

这是我的脚本代码

代码语言:javascript
复制
   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',
  })
})
}

这是我的删除函数

代码语言:javascript
复制
    const deleteCustomer = (id) => {
  for (let i = 0; i < tableData.value.length; i++) {
    if (tableData.value[i].id === id) {
      tableData.value.splice(i, 1);
    }
  }
};

您可以单击以查看屏幕快照输出。

EN

回答 1

Stack Overflow用户

发布于 2022-03-22 08:30:45

当您单击“是”时,将执行open函数的.then()部分。在这个块中,您需要调用delete函数。

您还需要将id传递给open()函数。就像open(id)

this.deleteCustomer(id)或者只是deleteCustomer(id)

代码语言:javascript
复制
const open = (id) => { // pass the id
    ElMessageBox.confirm(
'Do you want to continue the deletion?',  
{
  confirmButtonText: 'Yes',
  cancelButtonText: 'No',
  type: 'warning',
  center: true,     
})
.then(() => {
  // here you can call the delete function. 
  // this is the part that is executed when you click yes
  this.deleteCustomer(id) // use the id
  ElMessage({
    type: 'success',
    message: 'Deletion completed',
  })
})
.catch(() => {
  ElMessage({
    type: 'info',
    message: 'Deletion canceled',
  })
})
}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71558373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档