elementUI之MessageBox弹框

引入方式:
//全局注册 
	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()
常用参数:
参数说明类型可选值默认值
titleMessageBox 标题string
messageMessageBox 消息正文内容string / VNode
dangerouslyUseHTMLString是否将 message 属性作为 HTML 片段处理booleanfalse
type消息类型,用于显示图标stringsuccess / info / warning / error
iconClass自定义图标的类名,会覆盖 typestring
customClassMessageBox 的自定义类名string
callback若不使用 Promise,可以使用此参数指定 MessageBox 关闭后的回调function(action, instance),action 的值为’confirm’, ‘cancel’或’close’, instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法
showCloseMessageBox 是否显示右上角关闭按钮booleantrue
beforeCloseMessageBox 关闭前的回调,会暂停实例的关闭function(action, instance, done),action 的值为’confirm’, ‘cancel’或’close’;instance 为 MessageBox 实例,可以通过它访问实例上的属性和方法;done 用于关闭 MessageBox 实例
distinguishCancelAndClose是否将取消(点击取消按钮)与关闭(点击关闭按钮或遮罩层、按下 ESC 键)进行区分booleanfalse
lockScroll是否在 MessageBox 出现时将 body 滚动锁定booleantrue
showCancelButton是否显示取消按钮booleanfalse(以 confirm 和 prompt 方式调用时为 true)
showConfirmButton是否显示确定按钮booleantrue
cancelButtonText取消按钮的文本内容string取消
confirmButtonText确定按钮的文本内容string确定
cancelButtonClass取消按钮的自定义类名string
confirmButtonClass确定按钮的自定义类名string
closeOnClickModal是否可通过点击遮罩关闭 MessageBoxbooleantrue(以 alert 方式调用时为 false)
closeOnPressEscape是否可通过按下 ESC 键关闭 MessageBoxbooleantrue(以 alert 方式调用时为 false)
closeOnHashChange是否在 hashchange 时关闭 MessageBoxbooleantrue
showInput是否显示输入框booleanfalse(以 prompt 方式调用时为 true)
inputPlaceholder输入框的占位符string
inputType输入框的类型stringtext
inputValue输入框的初始文本string
inputPattern输入框的校验表达式regexp
inputValidator输入框的校验函数。可以返回布尔值或字符串,若返回一个字符串, 则返回结果会被赋值给 inputErrorMessagefunction
inputErrorMessage校验未通过时的提示文本string输入的数据不合法!
center是否居中布局booleanfalse
roundButton是否使用圆角按钮booleanfalse
使用分析:
//!!MessageBox可以展示简单的信息内容,如果要展示复杂的内容,使用Dialog组件
this.$msgbox.alert('详细描述','标题',{
  //这里设置其他的参数
  title:'标题'//如果已经设置了标题,又写了title属性,会把之前的覆盖
  message:'详情描述'//同上
  dangerouslyUseHTMLString:true; //默认是false 这个还是尽量不要用 可以里边写html代码片段
  type:success / info / warning / error  //默认没有,详细描述前边是否需要提示图标
  iconClass:'el-icon-setting'  //这里自定义一个elementui的icon图标 会把type设置的覆盖。
  customClass:'自定义的类' //可以写一个自定义的类名 可以更改MessageBox的样式,但是有scoped不生效
  callback:()=>{//这里写Message框被关闭时执行的代码} //不使用Promise的话,可以用这个在Message框被关闭时执行一些代码
  showClose:true(默认值)  //是否显示msgbox右上角的关闭按钮(x);
  beforeClose:function(action, instance, done){} //action的值为'confirm', 'cancel'或'close'(注意点:写了beforeClose 就必须得调用done() 否则不会往下执行) close只有distinguishCancelAndClose为true的时候才会有这个属性名
  distinguishCancelAndClose(取消区别和关闭)false(默认值)//是否将取消(点击取消按钮)与关闭(点击关闭按																													钮或遮罩层、按下 ESC 键)进行区分
  lockScroll:true(默认值) //是否在显示msgbox时 锁定body 不能滚动
  showCancelButton:boo  ,//是否显示取消按钮  false(以 confirm 和 prompt 方式调用时为 true)
  showConfirmButton:true(默认值) ,//是否显示确定按钮
  cancelButtonText:'取消按钮文本', //设置取消按钮的文本
  confirmButtonText:'设置确定按钮文本' //设置确定按钮的文本
  cancelButtonClass:'自定义类名' // 可以写自己想要的样式。!!注意 有scoped 样式不生效
  confirmButtonClass:'自定义类名' // 可以修改自己想要的样式 !!注意 有scoped 样式不生效
  closeOnClickModal:true(默认值) // 是否可以通过点击遮罩层来关闭msgbox(alert 方式调用时为 false)
  closeOnPressEscape:true(默认值) //是否支持esc按键来关闭msgbox(alert 方式调用时为 false)
  closeOnHashChange:true(默认值) //页面跳转时 是否关闭msgbox
  roundButton:false(默认)  //按钮是否圆角
  center:false(默认) //内容是否居中
  closeOnHashChange:true(默认) //是否在 hashchange 时关闭 msgbox
 	showInput:false(以 prompt 方式调用时为 true//是否显示输入框
  inputPlaceholder:'要保留的输入框提示'  //输入框的占位符
  inputType:text(默认) //输入框类型
  inputValue:'输入框的初始文本'  //默认自带的文本内容 会覆盖 inputPlaceholder设置的内容
  inputPattern:regexp. //正则表达式
  inputValidator:()=>{} //输入框的校验函数。可以返回布尔值或字符串(need return),若返回一个字符串(成为提示														信息), 则返回结果会被赋值给 inputErrorMessage
  inputErrorMessage:''  //设置 校验未通过时的提示文本
  
})

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ElementUIMessageBox 弹框中,可以通过传入一个 Vue 组件作为参数来自定义弹框的内容。如果你想要在自定义组件中生成多个复选框,可以使用 v-for 指令来实现循环生成。 以下是一个示例代码,演示了如何在自定义组件中循环生成多个复选框: ``` <template> <div> <p>{{ message }}</p> <el-checkbox-group v-model="checkedList"> <el-checkbox v-for="item in options" :key="item.value" :label="item.value">{{ item.label }}</el-checkbox> </el-checkbox-group> <div> <el-button @click="handleConfirm">确定</el-button> <el-button @click="handleCancel">取消</el-button> </div> </div> </template> <script> export default { props: { message: { type: String, default: '' }, options: { type: Array, default: () => [] } }, data() { return { checkedList: [] } }, methods: { handleConfirm() { this.$emit('confirm', this.checkedList) }, handleCancel() { this.$emit('cancel') } } } </script> ``` 在这个组件中,我们使用了一个 el-checkbox-group 组件来实现多选框,使用 v-model 指令来绑定选中的值。然后使用 v-for 指令循环生成多个 el-checkbox 组件。 然后在调用 MessageBox 时,将这个组件作为参数传入,并传入 options 数组来提供选项列表: ``` <template> <div> <el-button @click="showDialog">显示自定义弹框</el-button> </div> </template> <script> import MyMessageBox from '@/components/MyMessageBox' export default { components: { MyMessageBox }, data() { return { options: [ { label: '选项1', value: 'option1' }, { label: '选项2', value: 'option2' }, { label: '选项3', value: 'option3' } ] } }, methods: { showDialog() { const h = this.$createElement const messageBox = this.$msgbox({ title: '自定义弹框', message: h(MyMessageBox, { props: { message: '请选择一个或多个选项:', options: this.options }, on: { confirm: (checkedList) => { messageBox.close() console.log(checkedList) }, cancel: () => { messageBox.close() } } }), showCancelButton: true, showConfirmButton: true, cancelButtonText: '取消', confirmButtonText: '确定' }) } } } </script> ``` 这样就可以在自定义组件中循环生成多个复选框了。注意,这里我们在 MyMessageBox 组件中添加了一个 options 属性,用于传递选项列表。在调用 MessageBox 时,我们也需要传入这个 options 属性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值