Axios Processing HTTP Requests

Source: Internet
Author: User

In the handling of HTTP requests, the use of Vue-resource has been deprecated, but the use of the latest Axios, the following is a simple introduction.

Installation

Using node

Using CDN

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

Basic use method GET request
//Make a request for a user with a given IDAxios.Get('/user?id=12345'). Then (function (response) {Console.log (response); })  .Catch(function (Error) {Console.log (error); });//optionally the request above could also is done asAxios.Get('/user', {    params: {ID:12345}}). Then (function (response) {Console.log (response); })  .Catch(function (Error) {Console.log (error); });

POST request
Axios.post ('/user', {    'Fred',     ' Flintstone '   })  . Then (function (response) {    Console.log (response);  })  . Catch (function (Error) {    console.log (error);  });

Execute multiple requests at the same time
function Getuseraccount () {  return Axios.  Get('/user/12345');} function Getuserpermissions () {  return Axios.  Get('/user/12345/permissions');} Axios.all ([Getuseraccount (), Getuserpermissions ()])  . Then (Axios.spread (function (acct, perms) {     // Both Requests(  )));

The use of this method is actually the same as the original Ajax, one can understand.

Reference article: https://juejin.im/entry/587599388d6d810058a7a41a

Axios Processing HTTP Requests

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.