About interception of Axios request and response interception in vue and react

     In front-end and back-end data interaction, we usually use axios to send requests, sometimes cross-domain, but we can configure a reverse proxy to solve this problem; for example, requests starting with / ele can use server proxy for what we want The server that sent the request, and then set it in the axios request interception, which will save us the need to add / ele for all subsequent axios requests. The specific operation method is as follows:
    request interception:

axios.interceptors.requet.use(config=>{

config.url = "ele"+config.url

  retuen config (release)
))

Response interception:

axios.intercptors.response.use(res=>{

  return res.data

})

Because the data returned by the axios request will be placed in the data so that the returned data is directly parsed, so there is one step less resolution process during the previous rendering

Of course, there are other processes that can also use Axios' request and response interception as needed.

  

Guess you like

Origin www.cnblogs.com/bamboopanders/p/12724558.html