3-2 Axios Basic Introduction

Source: Internet
Author: User

1. Static references

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

2.NPM mode installation (recommended)

$ npm Install Axios--save-save     ==> is a dependencies node that adds package information to a Package.json that represents a package that is dependent on publishing. -save-dev ==> is a devdependencies node that adds package information to a Package.json and represents a package that is dependent on development.

3. Eight APIs (details: Https://www.npmjs.com/package/axios

1.axios.request (config) 2.axios.get (url[, config]) 3.axios.delete (url[, config]) 4.axios.head (url[, config]) 5. Axios.options (url[, config]) 6.axios.post (url[, data[, config]) 7.axios.put (url[, data[, config]) 8.axios.patch (url[ , data[, Config])

4. Receive Response information

Axios.get ('/user/12345 '). Then (function (response) {    console.log (response.data);         Response Data    Console.log (response.status);       Status Code    console.log (response.statustext);   HTTP status information for the response of the server    Console.log (response.headers);      Response Head    Console.log (response.config);       provided to ' Axios ' the request configuration});

5. Multiple interfaces are called together

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 is now complete});

Two. Common requests

New Vue ({//Global intercept mounted:function () {///request before axios.interceptors.request.use (config =}            Console.log ("before request");        return config;            })//Intercept The response request Axios.interceptors.response.use (response = {Console.log ("Before request response requests")        return response; })}, methods: {//Get request Get:function () {axios.get ("Package.json", {param                S: {userId: "999"}, headers: {token: "Alan"            }}). Then (res = {this.msg = Res.data;            }). catch (Error = {//catch is catch exception this.msg = "Error" + error;                })},//Post request Post:function () {axios.post ("Package.json", {///Parameters          UserId: "888"},{headers: {token: "Alanpost"      }}). Then (res = {this.msg = Res.data;            }). catch (Error = {//catch is catch exception this.msg = "Error" + error;                })},//Axios the underlying configuration http:function () {axios ({url: "Package.json",                Method: "Get",//Post parameter data: {urseid: "101"}, Get parameter params: {userId: "102",}, headers: {token: "http"}}).            Then (res = {this.msg = Res.data; })        }    }})

3-2 Axios Basic Introduction

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.