I. INTRODUCTION
Axios is based on the promise of a HTTP library, you can use the browser and node.js in.
We can provide the following services:
1, from the browser to create XMLHttpRequests
2, create http request from node.js
3, support PromiseAPI
4, to intercept the request and response
5, the data conversion request and response data
6, a cancellation request
7, the data is automatically converted JSON
8, client support defense XSRF
Option two:
1, axios installation:
Installation command; npm install axios
2, axios five kinds of requests:
1⃣️get: more commonly used to retrieve data
No arguments
A mode: Axios ({Methods: 'GET' , URL: '/ ULR' })
Second way: axios.get ( '/ URL')
Parameters way a: axios.get ( '/ url', {params: {id: 12}}) // address of the actual request is localhost: 8080 / url id = 12 ? Second way: Axios ({ Methods: 'GET ', URL:' URL ', the params: { ID: 12 is } })
2⃣️post: Main submitting form data and upload files
Data} = {the let the let config = {} way a: axios.post ( '/ url', data, config) Second way: Axios ({ Methods: 'POST', URL: '/ URL', Data: Data, config : config })
where there are two data formats form-data (image upload, file upload) applicition / json (more popular)
above two methods are appliction / json format
follows as: data-form
the let = new new formData the formData ()
the let = {data
ID: 12 is
}
for (in the let Key data) {
formData.append (Key, data [Key]) // bedstead form-data format data
}
Axios ({
Methods: 'POST',
URL: '/ URL',
Data: formData
})
This request is issued after the request header can be viewed inside the content-type of the request in the browser: to form form-data
All data is updated 3⃣️put
The post request and similar, but different request method
4⃣️patch only the changed data is updated
The post request and similar, but different request method
5⃣️delete deletion request (url parameter can also be placed on the post and on the same body of the request)
axios.delete ( '/ url', {params: {id: 12}}) are important parameters in the url params
axios.delete ( '/ url', {data: {id: 12}}) in a body parameter params to request data on the line