首页 > 其他 > 详细

element ui消息弹窗优化--禁止多次弹出

时间:2020-03-28 15:03:55      阅读:358      评论:0      收藏:0      [点我收藏+]

技术分享图片

上图是多次点击弹出警告框的效果,按照正常的理解,只要弹出过一次,后面不管怎么点都不应该在弹出,用原来的消息体即可,可惜element ui没有做这方面的处理,因此只能自己封装了

// element ui message封装,避免同一消息反复弹出
import { Message } from ‘element-ui‘

const showMessage = Symbol(‘showMessage‘)

class OnlyMessage {
	success (options, single = true) {
		this[showMessage](‘success‘, options, single)
	}

	warning (options, single = true) {
		this[showMessage](‘warning‘, options, single)
	}

	info (options, single = true) {
		this[showMessage](‘info‘, options, single)
	}

	error (options, single = true) {
		this[showMessage](‘error‘, options, single)
	}

	[showMessage] (type, options, single) {
		if (single) {
			if (document.getElementsByClassName(‘el-message‘).length === 0) {
				Message[type](options)
			}
		} else {
			Message[type](options)
		}
	}
}

export default new OnlyMessage()

  保存为onlyMsgbox.js

main.js中引入

import OnlyMessage from ‘./utils/onlyMsgbox‘
Vue.prototype.$message = OnlyMessage

  需要的地方使用

this.$message.success(‘成功消息‘)
this.$message.warning(‘警告消息‘)
this.$message.info(‘普通信息‘)
this.$message.error(‘错误消息‘)

  

 

element ui消息弹窗优化--禁止多次弹出

原文:https://www.cnblogs.com/diantao/p/12587305.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!