以下是使用 Vue.js 中的 a-popconfirm 组件实现删除功能的示例代码:

<a-popconfirm
  title='确认删除该节点及其子节点(包含关联图书)?'
  ok-text='确定'
  cancel-text='取消'
  @confirm='confirm'
>
  <a @click='handleDelete(record.id)'>删除</a>
</a-popconfirm>
confirm() {
  del(this.url.remove, {id: this.ids[0]}).then(res => {
    this.getTree();
    this.tableData = this.tableData.filter(bookType => {
      return bookType.id !== this.ids[0];
    })
  });
}

handleDelete(id) {
  this.ids[0] = id;
},

// 后端代码示例
List<TrainBookType> list = this.trainBookTypeService.lambdaQuery().eq(TrainBookType::getParentId, id).list();
        if (list.size() > 0) {
            list.forEach(a -> deleteBookParent(a.getId()));
        }
        this.trainBookTypeService.removeById(id);

当点击“删除”按钮时,会触发 `handleDelete` 方法,将当前节点的 id 传递给 `confirm` 方法。`confirm` 方法调用后端接口进行删除操作。如果删除操作成功,则更新前端页面。

如果删除操作失败,可能是以下原因导致的:

  • 前端代码没有正确触发删除操作
  • 后端接口没有正确处理删除请求
  • 后端代码存在逻辑错误

建议先检查前端代码是否正确触发了删除操作,并且后端接口是否能够正确处理删除请求。如果问题依然存在,请检查后端代码并查看日志信息。

Vue.js a-popconfirm 组件删除功能实现及常见问题排查