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])
5. Compatibility processing
The project found that phones in Android 4.3 and below do not support the use of Axios, mainly the inability to use promise. Add the following polyfill to it.
Installing Es6-promise in the project
CNPM Install Es6-promise--save-dev
At the beginning of axios.min.js, add
Require (' es6-promise '). Polyfill ();
Ok!
Original address: https://www.cnblogs.com/leaf930814/p/6807318.html
Compatibility handling of Axios