基础用法

TIP

从设计上来说,MessageBox 的作用是美化系统自带的 alert、confirm ,因此适合展示较为简单的内容。 如果需要弹出较为复杂的内容,请使用 Modal。

包含状态图标的消息弹出框

自定义message内容

全局方法

如果你完整引入了 Element,它会为 app.config.globalProperties 添加如下全局方法:$msgbox、 $alert、 $confirm 。

因此在 Vue 实例中可以采用本页面中的方式来调用MessageBox。 参数如下:

  • $msgbox(options)
  • $messageBox(options)
  • $alert(options)
  • $confirm(options)

MessageBox Options

名称类型可选值默认值说明
titlestring——MessageBox 的标题
message`stringVNode(() => VNode)`—
close-on-click-modalbooleantrue | falsetrue是否可通过点击遮罩层关闭 MessageBox
use-html-stringbooleantrue | falsefalse是否将 message 作为 HTML 片段处理
show-cancel-buttonbooleantrue | falsetrue是否显示取消按钮
show-confirm-buttonbooleantrue | falsetrue是否显示确定按钮
show-closebooleantrue | falsetrue是否显示关闭按钮
zIndexnumber--0自定义层级
cancel-button-textstring—取消取消按钮的文本内容
confirm-button-textstring—确认确定按钮的文本内容
cancel-button-classstring——取消按钮的自定义类名
confirm-button-classstring——确定按钮的自定义类名
fieldstringconfirm | alertconfirmmessageBox的类型
custom-classstring——MessageBox 的自定义类名
custom-styleCSSProperties——MessageBox 的自定义内联样式
lock-scrollbooleantrue | falsefalse是否在 MessageBox 出现时将 body 滚动锁定
icon`stringVNode(() => VNode)`—
callbackfunction(action, instance),action 的值为'confirm', 'modal', 'cancel'或'close', instance 为 MessageBox 实例, 可以通过它访问实例上的属性和方法——若不使用 Promise,可以使用此参数指定 MessageBox 关闭后的回调
before-closefunction(action, instance, done),action 的值为'confirm', 'modal', 'cancel'或'close', instance 为 MessageBox 实例, 可以通过它访问实例上的属性和方法, done用于关闭 MessageBox 实例———
has-loadingbooleanfalse—使用before-close时是否需要再confirm按钮处增加loading,调用done关闭loading
title-hiddenbooleanfalse—设置title超出后自动换行还是隐藏
transition-namestring—'m-message-box--fade'设置动画
sizestring—'medium'按钮大小

最近更新于: