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);
})
}
}
});