import { Message } from 'element-ui'; let messageInstance = null; const resetMessage = (options) => { if(messageInstance) { messageInstance.close() } messageInstance = Message(options) }; ['error','success','info','warning'].forEach(type => { resetMessage[type] = options => { if(typeof options === 'string') { options = { message:options } } options.type = type return resetMessage(options) } }) export const message = resetMessage
建立js文件
resetMessage.jsimport { message } from '../../utils/resetMessage';
引入js文件
message.error(errorMsg || '网络异常请稍后再试', '错误');
使用即可
标签:resetMessage,element,messageInstance,ui,message,js,type,options From: https://www.cnblogs.com/xiaobaizitaibai/p/17698829.html