美文网首页
element-plus

element-plus

作者: 夏晶晶绿 | 来源:发表于2023-06-11 11:00 被阅读0次
    1. 封装message(默认只显示一个msg)
    // dcMsg.js
    import { ElMessage  } from "element-plus";
    
    
    let msgInstance = null;
    function dcMsg(options,single=true) {
      if(msgInstance&&single){
        msgInstance.close();
      }
      msgInstance = ElMessage({
        ...options,
      });
      return msgInstance
    }
    
    // 添加方法
    dcMsg.info = (options,single) => {
      return dcMsg({type:'info',message:options?.message?options?.message:options},single)
    }
    dcMsg.success = (options,single) => {
      return dcMsg({type:'success',message:options?.message?options?.message:options},single)
    }
    dcMsg.warning = (options,single) => {
      return dcMsg({type:'warning',message:options?.message?options?.message:options},single)
    }
    dcMsg.error = (options,single) => {
      return dcMsg({type:'error',message:options?.message?options?.message:options},single)
    }
    
    dcMsg.closeAll=()=>{
      ElMessage.closeAll()
    }
    
    export default dcMsg;
    
    
      // 使用方法
      import dcMsg from '@/xxx/dcMsg'
    
      msgInstance=dcMsg({type:'warning',message:'提示信息'})
      msgInstance=dcMsg.warning('提示信息')
    
      //关闭
      msgInstance&&msgInstance.close()
      dcMsg.closeAll()
    

    相关文章

      网友评论

          本文标题:element-plus

          本文链接:https://www.haomeiwen.com/subject/ncbxydtx.html