- 封装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()
网友评论