axios 可以单独使用, 通过 cdn 引入 axios.JS 文件即可使用.
用 script 引入
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
1,axios 提供了一下几种请求方式
2,axios 常用的 get 和 post 请求实例:
- // get:
- axios.get("Sevlet_List")
- .then(function(res) {
- that.items = res.data.result;
- console.log(that.items)
- });
- // post :
- var param = new URLSearchParams(); // 为了解决兼容问题, 先声明一个对象
- param.append("gid",gid); // 给对象赋值
- axios.post("Servlet_details",param) // 然后把这个对象传递给后台
- .then(function(res){
- that.title = res.data.result[0].gname;
- })
3, 说明
Axios 是一个基于 Promise(ES6 中用于处理异步的) 的 HTTP 库, 用于浏览器和 node.JS 中, API.
● 浏览器中创建 XMLHttpRequests
● 从 node.JS 中创建 http 请求
● 支持 Promise API 拦截请求和响应转换
● 请求数据和响应数据取消
● 请求自动转换 JSON 数据
● 客户端支持防御 XSRF
来源: http://www.css88.com/qa/vue-js/14700.html