import Vue from 'vue' import { MessageBox, Notification, } from 'element-ui' //将错误提示改为Message居中 function notifyClone(options){ if(typeof options == 'object' && options.type == 'error'){ errorNotify(options) return; } return Notification(options) } //错误实现函数 let errorNotify=options =>{ if(typeof options == 'string' || //Vnode的判断 (typeof options == 'object' && options.hasOwnProperty('componentOptions'))){ options = {message:options} } options.title = options.title||"错误" options.type = 'error' options.confirmButtonText = '确定' return MessageBox.alert(options.message,options) } export default function rewriteNotify(){ ['success', 'warning', 'info'].forEach(type => { notifyClone[type] = function(options){ if(typeof options == 'string' || //Vnode的判断 (typeof options == 'object' && options.hasOwnProperty('componentOptions'))){ options = {message:options} } options.type = type return Notification(options) } }) notifyClone['close']=function(id, userOnClose){ Notification.close(id, userOnClose) } notifyClone['closeAll'] = ()=>Notification.closeAll() notifyClone['error'] = errorNotify // Vue.prototype.$notify = notifyClone }