文章目录
- 主要使用 beforeClose 方法实现 loading 的效果
- beforeClose MessageBox 关闭前的回调,会暂停实例的关闭
function(action, instance, done)
1. action 的值为'confirm', 'cancel'或'close'。
2. instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法。
3. done 用于关闭 MessageBox 实例。
- 具体实现:(
this.$confirm、this.$alert、 this.$prompt
实现方法一样)
this.$prompt('名称', '新建表单', {
confirmButtonText: '确定',
cancelButtonText: '取消',
beforeClose: async (action, ctx, close) => {
if (action !== 'confirm') {
close();
return;
}
ctx.confirmButtonLoading = true;
try {
await this.createApi(ctx.inputValue);
close();
} catch (error) {}
ctx.confirmButtonLoading = false;
},
});
- 实现前:

- 实现后:
