Axios请求参数形式 Types of URL Parameters by Axios
Params
If we use params, the data exposed in url and It is not safe sometimes. For example, if we are using axios.get() and axios.post(…,{params:{}})
Body
form-data
The data can be a file or key/value.x-www-form-urlencoded
The data can only be key/value and using & to connect.name=zhang && age=12Raw
It can be various types, like file/xml/json/text.
Example
When we send post request through axios, the default method as following.
But in Jquery is like:
If we want to change Json to form-urlencoded, we can do the following.
var params = new URLSearchParams();
params.append('param1', 'value1');
params.append('param2', 'value2');
axios.post('/foo', params);or using query-stringfy
axios.post('/',qs.stringify({...}))Notice: qs is different from json
qs.stringify => name=a&age=18
JSON.stringify => {'name':'a','age':18}