引入方式:
Vue.prototype.$msgbox=MessageBox;
Vue.prototype.$alert/$confirm/$prompt=MessageBox.alert/confirm/prompt;
this.$msgbox.alert/confirm/prompt() this.$alert/$confirm/$prompt()
import { MessageBox } from 'element-ui';
MessageBox.alert/confirm/prompt()
常用参数:
| | | | |
---|
参数 | 说明 | 类型 | 可选值 | 默认值 |
title | MessageBox 标题 | string | — | — |
message | MessageBox 消息正文内容 | string / VNode | — | — |
dangerouslyUseHTMLString | 是否将 message 属性作为 HTML 片段处理 | boolean | — | false |
type | 消息类型,用于显示图标 | string | success / info / warning / error | — |
iconClass | 自定义图标的类名,会覆盖 type | string | — | — |
customClass | MessageBox 的自定义类名 | string | — | — |
callback | 若不使用 Promise,可以使用此参数指定 MessageBox 关闭后的回调 | function(action, instance),action 的值为’confirm’, ‘cancel’或’close’, instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法 | — | — |
showClose | MessageBox 是否显示右上角关闭按钮 | boolean | — | true |
beforeClose | MessageBox 关闭前的回调,会暂停实例的关闭 | function(action, instance, done),action 的值为’confirm’, ‘cancel’或’close’;instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法;done 用于关闭 MessageBox 实例 | — | — |
distinguishCancelAndClose | 是否将取消(点击取消按钮)与关闭(点击关闭按钮或遮罩层、按下 ESC 键)进行区分 | boolean | — | false |
lockScroll | 是否在 MessageBox 出现时将 body 滚动锁定 | boolean | — | true |
showCancelButton | 是否显示取消按钮 | boolean | — | false(以 confirm 和 prompt 方式调用时为 true) |
showConfirmButton | 是否显示确定按钮 | boolean | — | true |
cancelButtonText | 取消按钮的文本内容 | string | — | 取消 |
confirmButtonText | 确定按钮的文本内容 | string | — | 确定 |
cancelButtonClass | 取消按钮的自定义类名 | string | — | — |
confirmButtonClass | 确定按钮的自定义类名 | string | — | — |
closeOnClickModal | 是否可通过点击遮罩关闭 MessageBox | boolean | — | true(以 alert 方式调用时为 false) |
closeOnPressEscape | 是否可通过按下 ESC 键关闭 MessageBox | boolean | — | true(以 alert 方式调用时为 false) |
closeOnHashChange | 是否在 hashchange 时关闭 MessageBox | boolean | — | true |
showInput | 是否显示输入框 | boolean | — | false(以 prompt 方式调用时为 true) |
inputPlaceholder | 输入框的占位符 | string | — | — |
inputType | 输入框的类型 | string | — | text |
inputValue | 输入框的初始文本 | string | — | — |
inputPattern | 输入框的校验表达式 | regexp | — | — |
inputValidator | 输入框的校验函数。可以返回布尔值或字符串,若返回一个字符串, 则返回结果会被赋值给 inputErrorMessage | function | — | — |
inputErrorMessage | 校验未通过时的提示文本 | string | — | 输入的数据不合法! |
center | 是否居中布局 | boolean | — | false |
roundButton | 是否使用圆角按钮 | boolean | — | false |
使用分析:
this.$msgbox.alert('详细描述','标题',{
title:'标题',
message:'详情描述',
dangerouslyUseHTMLString:true;
type:success / info / warning / error
iconClass:'el-icon-setting'
customClass:'自定义的类'
callback:()=>{
showClose:true(默认值)
beforeClose:function(action, instance, done){}
distinguishCancelAndClose(取消区别和关闭):false(默认值);
lockScroll:true(默认值)
showCancelButton:boo ,
showConfirmButton:true(默认值) ,
cancelButtonText:'取消按钮文本',
confirmButtonText:'设置确定按钮文本'
cancelButtonClass:'自定义类名'
confirmButtonClass:'自定义类名'
closeOnClickModal:true(默认值)
closeOnPressEscape:true(默认值)
closeOnHashChange:true(默认值)
roundButton:false(默认)
center:false(默认)
closeOnHashChange:true(默认)
showInput:false(以 prompt 方式调用时为 true)
inputPlaceholder:'要保留的输入框提示'
inputType:text(默认)
inputValue:'输入框的初始文本'
inputPattern:regexp.
inputValidator:()=>{}
inputErrorMessage:''
})