Skip to content

MessageBox 消息确认框

命令式确认框,返回 Promise<boolean>。适合删除、发布等必须先获得用户选择的流程;多个调用会按先入先出顺序排队。

基础用法

数据驱动的确认动作

点击操作按钮查看不同的确认配置。

vue

异步关闭校验

beforeClose 可同步或异步返回 false 阻止关闭,适合提交前校验或保存:

js
const confirmed = await AuMessageBox.confirm({
  title: '保存并发布',
  message: '确认提交当前版本吗?',
  async beforeClose(action) {
    if (action !== 'confirm') return true;
    return await validateRelease();
  },
});

MessageBox API

方法

方法参数返回值说明
AuMessageBox(options)string / number / AuMessageBoxOptionsPromise<boolean>打开确认框
AuMessageBox.confirm(options)同上Promise<boolean>语义更明确的等价调用
AuMessageBox.close()void关闭当前确认框并以 false 完成 Promise

点击确定返回 true;点击取消、关闭按钮、遮罩或按 Escape 返回 falsebeforeClose 抛出的错误会使 Promise reject。

Options

配置说明类型默认值
title标题string''
message正文string / number必填
width确认框宽度string / numbermin(420px, calc(100vw - 32px))
confirmButtonText确定按钮文案string确定
cancelButtonText取消按钮文案string取消
confirmTextconfirmButtonText 的兼容别名string
cancelTextcancelButtonText 的兼容别名string
confirmButtonType确定按钮的 AuButton 类型AuButtonTypeprimary
showCancelButton是否显示取消按钮booleantrue
showClose是否显示右上角关闭按钮booleantrue
closeLabel关闭按钮的无障碍名称与提示string关闭
closeOnClickModal是否允许点击遮罩关闭booleanfalse
closeOnPressEscape是否允许按 Escape 关闭booleantrue
beforeClose关闭前守卫(action, options) => boolean | Promise<boolean>

action 的可选值为 confirmcancelclose

Aurora Plus · Vue 3 Component Library