element-ui重置$message使弹窗只能出现一次

场景:操作过程中连续点击按钮弹出很多错误提示 或者函数执行多次产生很多错误提示弹窗不友好,修改为只弹出最后一次的提示;

/**重置message,防止重复点击重复弹出message弹框 */
import { Message } from "element-ui";
let messageInstance = null;
let mainMessage = function DoneMessage(options) {
  //如果弹窗已存在先关闭
  if (messageInstance) {
    messageInstance.close();
  }
  messageInstance = Message(options);
}
let arr = ['success', 'warning', 'info', 'error'];
arr.forEach(function (type) {
  mainMessage[type] = function (options) {
    if (typeof options === 'string') {
      options = {
        message: options
      };
    }
    options.type = type;
    return mainMessage(options);
  };
});
export const message = mainMessage;
import {
  message
} from '@/script/common/message.js';
Vue.prototype.$message = message;

你可能感兴趣的:(element-ui重置$message使弹窗只能出现一次)