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

Web Design Tutorial (1): Steps and Overall Layout

<br /> Note: All texts, except those indicat...

Detailed process of getting started with docker compose helloworld

Prerequisites Compose is a tool for orchestrating...

React Native startup process detailed analysis

Introduction: This article takes the sample proje...

VSCode configuration Git method steps

Git is integrated in vscode, and many operations ...

A brief analysis of the responsiveness principle and differences of Vue2.0/3.0

Preface Since vue3.0 was officially launched, man...

MySQL storage engine basics

In the previous article, we talked about MySQL tr...

Mybatis paging plug-in pageHelper detailed explanation and simple example

Mybatis paging plug-in pageHelper detailed explan...

Essential knowledge for web development interviews and written tests (must read)

The difference between inline elements and block-...

CSS Skills Collection - Classics among Classics

Remove the dotted box on the link Copy code The co...

...

Getting Started Tutorial for Beginners ⑨: How to Build a Portal Website

Moreover, an article website built with a blog pro...

How to install mysql database in deepin 2014 system

Deepin 2014 download and installation For downloa...