What does axios do? (Practical venue)

 

1. What does axios do?

Official explanation: axios is a promise-based HTTP library that can be used in browsers and node.js (it feels useless)

 

Simple understanding: axios is responsible for interacting with the backend, getting and posting backend interface information, which is quite a window for the front and back ends.

 

2. Introduction to common functions

1. Create an http request, send the request to the backend and receive the returned data

感觉这个功能十分重要

2. Automatically convert JSON data (equivalent to deserializing the data)

Generally, the data format returned by the background gateway is json format, like this:

{"utData":{"content":[{"id":null,"dataTableId":"185247","rowContent":{"creator":"fieldadmin1_dev","code":"","createTime":"2021-01-21T05:36:11.000+0000","returnDataType":"string","enName":"dddd","functionType":"localGlobal","paramTypeList":"string","chName":"llll"},"creator":null,"createTime":null,"editor":null,"updateTime":null},{"id":null,"dataTableId":"185247","rowContent":{"creator":"fieldadmin1_dev","code":"","createTime":"2021-01-21T05:37:02.000+0000","returnDataType":"string","enName":"dddd222","functionType":"cloudGlobal","paramTypeList":"string","chName":"llll3333"},"creator":null,"createTime":null,"editor":null,"updateTime":null},{"id":null,"dataTableId":"185247","rowContent":{"creator":"fieldadmin1_dev","code":"","createTime":"2021-01-...

After passing through axios, the data becomes a JSON object, like this:

3. Process the returned data in a unified manner (equivalent to filtering the background data uniformly and then passing it to the front end)

For example, the data transmitted in the background may be too large. Use JSONbig.parse to process it uniformly to prevent loss of precision.

4. Intercept requests and responses

That is, before the front end sends a request, you can set up to automatically intercept the request, which is equivalent to adding conditions to the request.

When the backend returns data, you can set a certain backend interface that does not receive data.

Guess you like

Origin blog.csdn.net/qq_44646982/article/details/113366520