axios请求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
console.log(response.data);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers);
console.log(response.config);
})
.catch(function (error) {
console.log(error);
});
// 发送 POST 请求
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
}); axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
执行多个并发请求
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) {
// 两个请求现在都执行完成
}));
封装请求:
function ajax_post(url,data,that,callback){
axios({
method:"POST",
headers:{'Content-type':'application/json',},
url:URL+url,
data:data,
//withCredentials:true
}).then(function(res){
//alert('post:'+res)
console.log(url+'\tPost请求到:');
console.log(res);
//alert('post-response:'+res);
callback(that,res);
//ajax_get('/manage/getinfo',this);
}).catch(function(error){
alert('post失败')
console.log(error);
});
}
function ajax_get(url,that,callback){
axios({
method:"GET",
headers:{'Content-type':'application/json',},
url:URL+url,
withCredentials:true
}).then(function(res){
console.log(url+'\tGet请求到:')
console.log(res);
//alert('get:'+this.res);
callback(that,res);
}).catch(function(error){
alert('get下载失败')
console.log(error);
});
}
function ajax_post_params(url,data,that,callback=()=>{}){
axios({
method: 'post',
url: URL+url,
headers: {
'Content-type': 'application/x-www-form-urlencoded',
},
params:data,
})
.then(function(res){
//alert('post:'+res)
console.log(url+'\tPost请求到:');
console.log(res);
//alert('post-response:'+res);
callback(that,res);
//ajax_get('/manage/getinfo',this);
}).catch(function(error){
alert('post失败')
console.log(error);
});
}
axios请求的更多相关文章
- Vue框架axios请求(类似于ajax请求)
Vue框架axios get请求(类似于ajax请求) 首先介绍下,这个axios请求最明显的地方,通过这个请求进行提交的时候页面不会刷新 <!DOCTYPE html> <html ...
- nodejs-5.2 axios请求
1.npm官方文档:https://www.npmjs.com/package/axios 2.axios:用于 浏览器 和 node.js的基于Promise的HTTP客户端 请求 特征 从浏览器制 ...
- 10. vue axios 请求未完成时路由跳转报错问题
axios 请求未完成时路由跳转报错问题 前两天项目基本功能算是完成了,在公司测试时遇到了遇到了一个问题,那就是在请求未完成时进行路由跳转时会报错,想了几种办法来解决,例如加loading,请求拦截, ...
- axios请求本地的json文件在打包部署到子目录域名下,路径找不到
前言: 因为要同时部署两个项目,有一个是部署到域名下面的子目录下,如:https://xxx.com/siot-admin vue 项目中使用axios请求了本地项目的static文件夹下的json文 ...
- 记录一次axios请求造成的数组初始化失败
axios请求是一个异步的请求,简单来讲就是在做其他事情的时候可以把这个先放一边等其他的事情做完后再来做这件事件. 我之前这样调用了一个方法: mounted() { this.first() thi ...
- token回话保持,axios请求拦截和导航守卫以及token过期处理
1:了解token:有时候大家又说token令牌.整个机制是前端第一次登陆发送请求,后端会根据前端的用户名和密码, 通过一些列的算法的到一个token令牌, 这个令牌是独一无二的,前端每次发送请求都需 ...
- 解决在vue中axios请求超时的问题
查看更多精彩内容请访问我的新博客:https://www.cssge.com/ 自从使用Vue2之后,就使用官方推荐的axios的插件来调用API,在使用过程中,如果服务器或者网络不稳定掉包了, 你们 ...
- vue 路由拦截、axios请求拦截
路由拦截 项目中,有些页面需要登录后才能进入,例如,在某页面A,用户在操作前需要先进入登录页(此时需要将上一页的地址(/survey/start)作为query存入login页面的地址中,如: htt ...
- vue中Axios请求豆瓣API数据并展示到Swipe中
vue中Axios请求豆瓣API数据并展示到Swipe中 1.首先是安装Axios: 安装方法cnpm install axios --save 等待npm安装完毕: 2.在main.js中引入axi ...
- vue脚手架用axios请求本地数据
首先需要声明的是:本地请求,不用考虑跨域问题,这适用刚入坑的前端小白看,小白在做自己的项目时,通常都是用自己写的json数据,之后用axios请求过来,渲染到页面上. 1.cnpm install a ...
随机推荐
- Kotlin从入门到放弃
1.eclipse kotlin安装: http://blog.csdn.net/u014134488/article/details/50684922 2.Android Studio kotlin ...
- django 时区设置 redis token缓存策略
from django.utils.timezone import utcimport datetime datetime.datetime.utcnow().replace(tzinfo=utc)# ...
- js 模拟超级大LE透中头奖 统计中头奖需要购买的彩票次数以及购买总金额
<!DOCTYPE html> <html> <head> <title>超级大LE透模拟</title> </head> &l ...
- linux1
虚拟内存:内核通过磁盘上的存储空间来实现虚拟内存,这块区域称为交换空间.内核不断交换空间和实际的物理内存之间反复交换虚拟内存中的内容 linux运行中的程序叫做进程. 内核创建了第一个进程,叫做Ini ...
- HTML5 页面编辑API之Range对象
在 HTML5 中,一个 Range 对象代表页面上的一段连续区域.通过 Range 对象,可以获取或修改页面上的任何区域.包含获取,修改,删除和替换等操作. 一:获取range对象的值 Range对 ...
- jquery 改变img的src
jQuery修改img的src的方法: $("#img_id").attr("src","new_src"); 此语句的功能是:修改id为i ...
- ThinkPHP 5 验证码
<div> <form action="{:url('index/check')}" method="post"> <img sr ...
- 做一个有产品思维的研发:Scrapy安装
每天10分钟,解决一个研发问题. 如果你想了解我在做什么,请看<做一个有产品思维的研发:课程大纲>传送门:https://www.cnblogs.com/hunttown/p/104909 ...
- python类与对象-如何让对象支持上下文管理
如何让对象支持上下文管理 问题举例 一个telnet客户端的类TelnetClient, 调用实例的connect(),login(),interact方法 启动客户端与服务器交互,交互完毕后需要调用 ...
- filter与map函数
·filter()函数filter()函数包括两个参数,分别是function和list.该函数根据function参数返回的结果是否为真来过滤list参数中的项,最后返回一个新列表,如下例所示:&g ...