Vue3 uses axios interceptor to print front-end logs

Vue3 uses axios interceptor to print front-end logs

1. Introduction

Many times we need to debug the front end, that is, debug the interaction between the front-end and back-end interfaces. The common way is to log, such as console.log ('log content').

This method is actually OK for a single method, but for multiple interfaces and methods, this debugging method is a little worse. Also, methods have an execution order, which sometimes affects debugging.

2. Use axios interceptor to print front-end logs

This is a more recommended method, that is, write it once and you don’t have to write console.log all the time.

Suddenly I thought of a sentence I often saw when doing tests:

It’s all about testing

To paraphrase this sentence, it's all about debugging.

1. Modify main.ts

Modify main.ts and add the following content:

html
/**
 * axios interceptor */
axios.interceptors.request.use(function (config) {
  console.log('Request parameters:', config);
  return config;
}, error => {
  return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
  console.log('Return result:', response);
  return response;
}, error => {
  console.log('Return error:', error);
  return Promise.reject(error);
});

2. Delete all console.log in home

3. Recompile and start again

Check the results as shown below:

This is the end of this article about Vue3 using axios interceptor to print front-end logs. For more relevant Vue3 using axios interceptor to print front-end logs, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the problem of Vue cross-domain axios asynchronous communication
  • Vue+axios sample code for uploading pictures and recognizing faces
  • How to encapsulate axios in Vue
  • Detailed explanation of Axios asynchronous communication in Vue

<<:  3 ways to add links to HTML select tags

>>:  How to choose between MySQL CHAR and VARCHAR

Recommend

How to insert pictures into HTML pages and add map index examples

1. Image formats supported on the WEB: GIF: can s...

Use of Linux xargs command

1. Function: xargs can convert the data separated...

Realization of real-time file synchronization between Linux servers

Usage scenarios For existing servers A and B, if ...

How to automatically start RabbitMq software when centos starts

1. Create a new rabbitmq in the /etc/init.d direc...

Vue directives v-html and v-text

Table of contents 1. v-text text rendering instru...

How to enable JMX monitoring through Tomcat

Build a simulation environment: Operating system:...

Detailed graphic tutorial on installing Ubuntu 20.04 dual system on Windows 10

win10 + Ubuntu 20.04 LTS dual system installation...

mysql 5.7.20 win64 installation and configuration method

mysql-5.7.20-winx64.zipInstallation package witho...

MySQL Best Practices: Basic Types of Partition Tables

Overview of MySQL Partitioned Tables As MySQL bec...

Use of docker system command set

Table of contents docker system df docker system ...

How to install Odoo12 development environment on Windows 10

Preface Since many friends say they don’t have Ma...

Solve the pitfall of storing boolean type values ​​in localstorage

LocalStorage stores Boolean values Today, when I ...

How to use CSS to display multiple images horizontally in the center

Let me first talk about the implementation steps:...