axios的使用
来源:互联网 发布:文本数据挖掘 编辑:程序博客网 时间:2024/05/19 23:24
二.axios的使用
1.安装
1>使用npm
npm install axios
2>使用bower
bower install axios
3>使用cdn
<script src="https://unpkg.com/axios/dist/axios.min.js"> </script>
2.demo
2.1.get请求
axios.get('/user?ID=123')
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error);
})
上面的也可以这样写:
axios.get('/user', { params: { ID: 123 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
2.2.执行post请求
axios.post('/user',{
firstName:'Fred',
lastName:'Flintstone'
})
.then(function(response){
console.log(response);
})
.catch(function(error){
console.log(error);
})
2.3.执行多个并发请求
function getUserAccount(){
return axios.get('/user/123');
}
function getUserPermissions(){
return axios.get('/user/123/permissions');
}
axios.all([getUserAccount(),getUserPermissions()])
.then(axios.spread(function(acct,perms){
//两个请求现在都执行完成
}))
3.可以向axios传递相关配置来创建请求
axios(config)
//发送POST请求
axios({
method:'post',
url:'/user/123',
data:{
firstName:'Fred',
lastName:'Flintstone'
}
})
- axios的使用
- axios的使用
- vue axios 的使用
- vue2 axios的使用
- axios的使用
- vue.js axios 的使用
- axios 使用
- 一些关于使用axios的心得
- 使用URLSearchParams处理axios发送的数据
- 使用axios上传照片的方法
- 基于vue-cli的vue项目之axios的使用5--axios方法发送请求
- 基于vue-cli的vue项目之axios的使用6--配置axios
- vue使用axios异步请求后端数据的使用
- vue-axios使用
- vue之axios使用
- vue-axios整合使用
- vue-cli 使用axios
- 使用axios上传照片
- C/C++学习之C提高----C数组的定义、类型、定义数组指针变量、多维数组的本质、多维数组做函数参数、将两个数组中的字符串copy到第三个数组
- VS2012/2013 工程在编译过程中遇到的一些问题?
- 自己搭建springweb工程
- java MD5算法工具类
- java语法基础练习题1
- axios的使用
- 《隐秩序:适应性造就复杂性》--摘录与评述
- qq列表拖拽效果 qq果冻效果 qq删除消息提醒 小红点 CAShapeLayer动画
- Leetcode416. Partition Equal Subset Sum
- [arc076f]Exhausted?
- IO流简单学习知识点
- PT项目-采购订单批量导入
- 初识负外边距在布局中的影响(1):基础理论
- Struts2框架学习---Three