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

MySQL 8.0.23 Major Updates (New Features)

Author: Guan Changlong is a DBA in the Delivery S...

Linux tac command implementation example

1. Command Introduction The tac (reverse order of...

JavaScript Basics Series: Functions and Methods

Table of contents 1. The difference between funct...

Detailed explanation of how to use the canvas operation plugin fabric.js

Fabric.js is a very useful canvas operation plug-...

jQuery realizes dynamic particle effect

This article shares the specific code of jQuery t...

Detailed analysis of mysql MDL metadata lock

Preface: When you execute a SQL statement in MySQ...

Basic operation tutorial of files and permissions in centos

Preface Before we begin, we should briefly unders...

Implementation of local migration of docker images

I've been learning Docker recently, and I oft...

How to query duplicate data in mysql table

INSERT INTO hk_test(username, passwd) VALUES (...

Detailed explanation of the four transaction isolation levels in MySQL

The test environment of this experiment: Windows ...

Six ways to increase your website speed

1. Replace your .js library file address with the...

MySQL 8.0.13 installation and configuration method graphic tutorial under win10

I would like to share the installation and config...