Solution to the problem of repeated pop-up of Element's Message pop-up window

Solution to the problem of repeated pop-up of Element's Message pop-up window

1. Use

Using element's message component in Vue

Use in Vue file

this.$message({
  message: "prompt message",
  type: "success"
})

Use in js file

import ElementUI from 'element-ui';

ElementUI.Message({
  message: 'prompt message',
  type: 'warning'
});

2. Solve the problem of repeated display of message pop-up windows

// message.js
/**
 * @Description: Override message mounting to implement private properties of Class* @param { String } options => message content* @param { Boolean } single => whether to display only one*/
import { Message } from 'element-ui';

const showMessage = Symbol('showMessage');

class DonMessage {
  success (options, single = false) {
    this[showMessage]('success', options, single);
  }
  warning (options, single = false) {
    this[showMessage]('warning', options, single);
  }
  info (options, single = false) {
    this[showMessage]('info', options, single);
  }
  error (options, single = true) {
    this[showMessage]('error', options, single);
  }

  [showMessage] (type, options, single) {
    if (single) {
      // Determine if Message already exists
      if (document.getElementsByClassName('el-message--error').length === 0) {
        Message[type](options);
      }
    } else {
      Message[type](options);
    }
  }
}

// Default export of private Message component export default new DonMessage();

Introduce where necessary

import DonMessage from '@/message' 

Use directly in js file

DonMessage.warning('Please log in') 

Mounted on the vue prototype

// main.js 
Vue.prototype.$message = DonMessage 
// Call this.$message.warning("Please log in") in the vue file

This is the end of this article about how to solve the problem of repeated pop-up of Element’s Message pop-up. For more information about repeated pop-up of Element’s Message pop-up, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue implements table pop-up component based on Element-ui
  • The whole process of implementing the summary pop-up window with Vue+Element UI
  • Steps for encapsulating element-ui pop-up components
  • Implementation of vue+elementui universal pop-up window (add+edit)
  • Solution to the failure of closing the dialog pop-up window in element-ui
  • Detailed explanation of the problem between pop-up windows using element ui and echarts in vue
  • Element modifies the implementation of the level of pop-up window components

<<:  MySQL encoding utf8 and utf8mb4 utf8mb4_unicode_ci and utf8mb4_general_ci

>>:  How to install and connect Navicat in MySQL 8.0.20 and what to pay attention to

Recommend

How to avoid duplication of data when inserting in MySql batch

Table of contents Preface 1. insert ignore into 2...

64-bit CentOs7 source code installation mysql-5.6.35 process sharing

First install the dependent packages to avoid pro...

win10 mysql 5.6.35 winx64 free installation version configuration tutorial

mysql 5.6.35 winx64 free installation version con...

A method of hiding processes under Linux and the pitfalls encountered

Preface 1. The tools used in this article can be ...

Basic usage of @Font-face and how to make it compatible with all browsers

@Font-face basic introduction: @font-face is a CSS...

Not a Chinese specialty: Web development under cultural differences

Web design and development is hard work, so don&#...

Detailed explanation of custom events of Vue components

Table of contents Summarize <template> <...

Use JavaScript to create page effects

11. Use JavaScript to create page effects 11.1 DO...

Which one should I choose between MySQL unique index and normal index?

Imagine a scenario where, when designing a user t...

Website front-end performance optimization: JavaScript and CSS

I have read an article written by the Yahoo team ...

Solve the scroll-view line break problem of WeChat applet

Today, when I was writing a small program, I used...

An example of implementing a simple infinite loop scrolling animation in Vue

This article mainly introduces an example of Vue ...

Summary of the differences and usage of plugins and components in Vue

The operating environment of this tutorial: Windo...