Compatibility of Axios

Source: Internet
Author: User

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

123456789 axios.post(‘/welfare‘, {     giftPackId: 1  })  .then(function (res) {    console.log(res);  })  .catch(function(res) {    console.log(res);  });

  

3. Send multiple concurrent Requests

123456789101112 functiongetUserAccount() {  returnaxios.get(‘/welfare‘);}functiongetUserPermissions() {  returnaxios.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:

12345678910111213 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

1 cnpm install es6-promise --save-dev

At the beginning of axios.min.js, add

1 require(‘es6-promise‘).polyfill();

Ok!

Compatibility of Axios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.