封装elementUI Message 组件, 避免连续多个请求接口报错,页面同时连续显示多个message弹窗

封装elementUI Message 组件, 避免连续多个请求接口报错,页面同时连续显示多个message弹窗


/**重置message,防止重复点击重复弹出message弹框 */
import { Message } from 'element-ui';
 
let messageInstance = null;
const norepeatMessage = (options) => {
    if(messageInstance) {
        messageInstance.close()
    }
    messageInstance = Message(options)
};
['error','success','info','warning'].forEach(type => {
    norepeatMessage[type] = options => {
        if(typeof options === 'string') {
            options = {
                message:options
            }
        }
        options.type = type
        return norepeatMessage(options)
    }
})
let messageup

export default  messageup = norepeatMessage

使用:在axios统一拦截中使用

	// import { Message } from 'element-ui'	
	import Message from '@bizComp/norepeatMessage'
	  Message({
            message: res.message || res.msg || 'Error',
            type: 'error',
            duration: 5 * 1000
          })

参考文章

你可能感兴趣的:(bug解决记录,elementui,javascript,前端)