I won't say much nonsense, let's just read the code~
// An highlighted block //http request interceptor( config =>{ const token = ('Tk_token') const user_id=('Tk_user_id') // = (); // = { // 'Content-Type':'application/x-www-form-urlencoded' // } if(token){ = {'token':token,'user_id':user_id} } (config); return config; }, err =>{ return (err); } )
Supplementary knowledge:Parameter issues when Vue and axios send background post requests
I started using vue-resource, but later I found that this has not been updated for a long time. The author has stopped updating, and even the author recommends using axios. So I will use axios. After changing it to axios, a problem arises: parameter problem.
What is the parameter question? When using vue-response to send post requests, the passed parameters are separated into the background one by one, such as passing parameters.
{ username:'name1', password:'pwd1' }
It is a very simple username and password. After vue-resource is passed to the background, the interface method parameters of the background are two, one is username and the other is password, both of which can be obtained separately; but axios is different. After axios comes to the background, it is an object with a map structure. You need to use the @RequestBody Map map to obtain it, and then take it out one by one from the map. This is also OK. But is there a way to make the parameters passed to the background of axios one by one? Of course there is.
The first method is URLSearchParams. Use this to add good parameters, and they will go to the background one by one, but this IE does not support it.
There is another way, that is, qs. There are two ways to introduce qs. One is to install it with npm, directly import it, and then use it; the other is to directly import it on the page, which is the method of <script src='js/'></script>, and then
Pay attention!
Pay attention here!
If it is introduced in the import method, we just use the call, but! ! !
Pay attention!
If it is the method of introducing js files, Qs is not qs, and Q is capitalized Q, that is.
Then it's OK!
The above article Vue requests to pass public parameters is all the content I share with you. I hope you can give you a reference and I hope you can support me more.