重写element-ui $message 解决消息多次弹出的问
2020-06-24 本文已影响0人
小枫学幽默
/***重写element-ui $message 解决消息多次弹出的问题**/
import {
Message
} from "element-ui";
let messageInstance = null;
const overrideMessage = (options) => {
if(messageInstance) {
messageInstance.close();
}
messageInstance = Message(options);
};
["error","success","info","warning"].forEach(type => {
overrideMessage[type] = options => {
if (typeof options === "string") {
options = {
message: options
};
}
options.type = type;
return overrideMessage(options);
};
});
/***重写message**/
Vue.use(ElementUI, {
size: "small",
zIndex: 3000
});
Vue.prototype.$message = overrideMessage;