Vant-UI Dialog 取消默认关闭事件时,一直转圈圈问题

2024-11-26 11:23:24

一. 问题

在使用 Vant-UI Dialog 组件时,想要实现一个效果:点击确定时,先调用后端接口,等返回结果后,再关闭弹框。

但是,在开发过程中,使用 beforeClose ,一直转圈圈 loading。

二. 解决方案

this.$dialog.confirm({
  title: "提示",
  message: "异步回调",
  beforeClose: (action, done) => {
    if (action === "cancel") {
      done(true); // 关闭弹框
    } else {
      new Promise((resolve) => {
        setTimeout(() => {
          if (action === "confirm") {
            done(true); // 关闭弹框
          }
        }, 1000);
      })
    }
  }
});

目录

相关推荐
关于调用微软Bing API推送链接时,报:errorcode 3 message ERROR!!! InvalidApiKey如何调用百度和微软必应链接收录APIMac安装nvm时,各种问题总结react-app-rewired中如何设置ant-design主题,以及不生效问题Variable @primary-color-hover is undefinedAnt-Design-Vue Form 中,对于多选下拉表表单时,重置时,表单未正确展示