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