Use window.onerror to detect project's global errors/network errors

Chicken Soup of the Day: Every moment you want to learn is your future self asking for help

After the web application is built, a dist folder will be generated. There are some js/css/pictures and other files in this folder. Generally speaking, when we deploy, we deploy all the contents of this dist folder to the server.

Suppose we are currently on page A, we need to load a.js, and to jump to page B, we need to load b.js

Assuming that the network is not good before the jump and cannot be loaded into b.js, an error that the resource cannot be found will be reported at this time! If we do not deal with this kind of error, then the user will click a button and there will be no response, and then the page will be stuck, which will greatly affect the experience!

At this time, we can use window.onerror to capture, and then it will be much better to give a network error prompt

window.onerror = () => {

        //

}

or

window.addEventListener('error', () => {

        //

})

reference

​​​​​​How to elegantly monitor the error reporting of Vue projects (4 ways) - Nuggets

Guess you like

Origin blog.csdn.net/qq_17335549/article/details/131898949