Solution to ElementUI's this.$notify.close() call not working

Solution to ElementUI's this.$notify.close() call not working

Requirement Description

The project first requires the user to select a question. After the selection, the Notification component of ElementUI is used to remind the user that the file format is being checked (it needs to be submitted to the backend first, checked by the backend, and then the results are returned to the frontend). If the format check is correct, the Notification is closed and a MessageBox (also a component of ElementUI) pops up to inform the user that the uploaded file cannot be undone.

Problem Description

After checking whether the file format is correct, you need to manually call the relevant function to remove the Notification. According to the official documentation, using this.$notify.close() did not work and no error was reported in the console.

Problem Analysis

After printing this.$notify in the console, you can enter the Notification related functions as shown below:

Code under the console Source panel

In the code, we can see which functions are encapsulated inside Notification, including the close() function, which requires two parameters, id and userOnClose. It is not difficult to see from the code that id is the id of Notification. For example, when there are multiple Notifications, they can be closed selectively; userOnClose can pass in a function, which is a bit like a callback function. Therefore, if you want to use the close() function, you must know the id of the Notification you want to close, which will be briefly discussed at the end of this article.
Looking down at the code, you can see that there is a closeAll() function, which does not require any parameters and closes all Notifications by traversing, which is suitable for the scenario of this project (only one Notification needs to be closed).

Problem Solving

For this project, just call this.$notify.closeAll() .

Question extension

The main thing is, if there are multiple Notifications, what should I do if I want to close one of them? I tried to understand notify.js and found that the id is basically a pattern like notification_seed , which is a string consisting of the notification_ string plus a number. Looking at the source code, we find that the initial seed is 1, which means that the id of the first instantiated Notification should be notification_1 . As shown in the figure:

insert image description here

Now the problem comes. I call the close() function and pass in two parameters that seem to be correct, but it doesn't work:

insert image description here

To prevent my misunderstanding of the id, I debugged it in the browser and found that the id in the instance (instance of Notification) was indeed the id I analyzed:

insert image description here

So I used the debugging tool in the developer tools to check the execution steps of the close() function in notify.js step by step. I found that there was no problem with the code or the logic. Finally, instances also removed the Notification with the corresponding id through the splice function, but the Notification on the page remained there and did not disappear (the main function is in the rectangular box).

insert image description here

The above are some of my personal attempts at analysis. Of course, due to my limited ability, I didn’t solve the problem in the end. Those who are interested can study it.

This is the end of this article about how to solve the problem of ElementUI's this.$notify.close() call not working. For more related Element this.$notify.close() call content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue solves the problem of line breaks in prompt information using $notify in element

<<:  MySQL 8.0.18 Hash Join does not support left/right join left and right join issues

>>:  Detailed explanation of Linux system software installation commands based on Debian (recommended)

Recommend

How to deploy a simple c/c++ program using docker

1. First, create a hello-world.cpp file The progr...

An article to understand operators in ECMAScript

Table of contents Unary Operators Boolean Operato...

Implement MySQL read-write separation and load balancing based on OneProxy

Introduction Part 1: Written at the beginning One...

Vue implements dynamic query rule generation component

1. Dynamic query rules The dynamic query rules ar...

How to set up scheduled tasks in Linux and Windows

Table of contents Linux 1. Basic use of crontab 2...

Example of using CSS to achieve floating effect when mouse moves over card

principle Set a shadow on the element when hoveri...

Whitespace processing in HTML/CSS and how to preserve whitespace in the page

Whitespace rules in HTML In HTML, multiple spaces...

HTML+CSS to achieve responsive card hover effect

Table of contents accomplish: Summarize: Not much...

CSS style reset and clear (to make different browsers display the same effect)

In order to make the page display consistent betwe...

How to forget the password of Jenkins in Linux

1.Jenkins installation steps: https://www.jb51.ne...

Detailed tutorial on installing MySQL 8 in CentOS 7

Prepare Environmental information for this articl...

Detailed explanation of the background-position percentage principle

When I was helping someone adjust the code today,...

vue-admin-template dynamic routing implementation example

Provide login and obtain user information data in...