elementui msg 提示一次

2021-04-12  本文已影响0人  肥羊猪

main.js

import resetMessage from "../stuPro/utils/resetMessage";
import ElementUI from "element-ui";
Vue.use(ElementUI);
Vue.prototype.$message = resetMessage; //挂载的话只能在vue.use(ElementUI)后面 ,否则无效

resetMessage.js

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 default resetMessage;

上一篇下一篇

猜你喜欢

热点阅读