原文地址:https://banggan.github.io/2019/01/04/axios总结/
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。在Vue中常用axios来做前后端的交互;
上一张git上的star值
特点
- 从浏览器中创建 XMLHttpRequests
- 从 node.js 创建 http 请求
- 支持 Promise API
- 拦截请求和响应
- 转换请求数据和响应数据
- 取消请求
- 自动转换 JSON 数据
- 客户端支持防御 XSRF
使用
安装:$ npm install axios cdn方式: src=“https://unpkg.com/axios/dist/axios.min.js”
基本使用:
Axios.method('url',[...data],options)
.then(function(res){})
.catch(function(err){})
合并请求:
例如:
//定义两个不不同的情请求
var q1 &