Vue.js Global Error Handling

  1. Vue.js Global Error Handling

There are two particularly relevant parts of the Vue.js API that you should be aware of: errorHandler and warnHandler. As you might have guessed, these are for handling errors and warnings, respectively. Simply set these handlers up before initializing your app.

Err is the JavaScript Error object that was thrown
vm is the relevant Vue instance
info is a string specifying in which part of the Vue lifecycle the error occurred. The same goes for warnHandler, except the first argument msg is a string containing the warning.

Notes: Assign a custom handler for runtime Vue warnings. Note this only works during development and is ignored in production. Link

Handling Error

in main.js

Vue.config.errorHandler = function(err, vm, info) {
  console.log(`Error: ${err.toString()}\nInfo: ${info}`);
}

Vue.config.warnHandler = function(msg, vm, trace) {
  console.log(`Warn: ${msg}\nTrace: ${trace}`);
}

#vuejs #error #handling #vue.js

Vue.js Global Error Handling
20.05 GEEK