First, Introduction
Look at the profile of the official website:
"Promise based HTTP client for the browser and node. js"
HTTP request client based on Promise, which can be used in both the browser and node. js.
Second, features:
1, send xmlhttprequests request in the browser;
2. Send HTTP requests in node. js;
3, support Promise API;
4, interception request and response;
5, conversion request and response data;
6. Automatic conversion of JSON data;
7, the client supports the protection of security from XSRF attacks;
Third, installation (official website)
Iv. Application
1. Send a GET request
Axios.get ('/welfare ', {
Params: {
Giftpackid:1
}
})
. Then (function (res) {
Console.log (RES);
})
. catch (function (res) {
Console.log (RES);
});
2. Send a POST request
Axios.post ('/welfare ', { giftpackid:1 }) . Then (function (res) { console.log (res); }) . catch (function (res) { console.log (res); });
3. Send multiple concurrent Requests
function Getuseraccount () { return axios.get ('/welfare ');} function Getuserpermissions () { return axios.get ('/getwelfare ');} Axios.all ([Getuseraccount (), Getuserpermissions ()]) . Then (Axios.spread (function (acct, perms) { //OK }));
4, in addition to the Axios also provides the following several request methods:
Axios.request (config) axios.get (url[, config]) axios.delete (url[, config) axios.head (url[, config]) axios.post (url[, data[, Config]]) axios.put (url[, data[, config]) axios.patch (url[, data[, Config])
Application of Axios