How to catch and handle global exceptions and errors in vuejs2.0 and submit them to the background

now there is a requirement that you need to catch page errors or failed data requests and submit them to the background for logging. How do you do this?

Apr.03,2021

learn about global error handling and component error handling:
https://cn.vuejs.org/v2/api/-sharperrorHandler
https://cn.vuejs.org/v2/api/-sharperrorCaptured

data requests fail to be submitted to the server, which you have to consider, especially if the client logging service and the data request service are at the same endpoint. For more information on how to intercept data request errors, please refer to the http component you rely on, such as axios . Slice:

// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (error) {
    // Do something with response error
    return Promise.reject(error);
  });
Menu