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 ...
随机推荐
- AngularJS_简介、特性及基本使用_及其工作原理
转自:angularJS 的工作原理 转自:通过<script>标签引入到 HTML 中,那么此时 Angular 就做为一个普通的 DOM 节点等待浏览器解析 当浏览器解析到这个节点时, ...
- [LeetCode] Search in a Binary Search Tree 二叉搜索树中搜索
Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST ...
- oracle统计数据时,涉及两个表的数据
SELECT t1.*,a.num FROM (SELECT SUM(t.total_profit) total_profit, SUM(t.main_business_income) main_bu ...
- Nginx 自定义404、500、502 页面
利用nginx的反向代理来实现 服务器404 和500 等状态码的自定义页面 1.nginx配置文件 nginx.conf 配置开启代理错误拦截 和配置页面 下划线部分 http { ...... ...
- 微信小程序里如何用阿里云上传视频,图片。。
纯手写,踩了半天多的坑干出来了... 网上也有对于阿里云如何在微信小程序里使用,但是很不全,包括阿里云文档的最佳实践里. 话不多说上代码了. upvideo(){ var aliOssParams = ...
- 20175320 2018-2019-2 《Java程序设计》第8周学习总结
20175320 2018-2019-2 <Java程序设计>第8周学习总结 教材学习内容总结 本周学习了教材的第十五章的内容,在这章中介绍了泛型和集合框架,着重讲了泛型类的概念,并介绍了 ...
- linux_grub resue模式恢复
//20190417 今天中午装linux的电脑崩了…… 一开始还以为是什么硬件问题,搞了半天,是更新的时候吧grub启动项弄坏了 行吧,没人教咱就上网搜,搞一下午搞出来了 ============= ...
- [Day18]集合框架Collection、迭代器、增强for循环以及泛型
1.集合 1.1集合-本身是一个存储的容器 集合类的基本接口是Collection接口,这个接口有两个基本方法 (1)boolean add(E element) 用于向集合中添加元素,如果添加元素确 ...
- [dev] Go的协程切换问题
子标题:runtime.Gosched() 是干嘛用的? 1. go程序都有一个环境变量,做线程数设置 GOMAXPROCS 2. 当协程数小于等于线程数的时候,程序行为上与多线程没有区别. 3. 当 ...
- RxSwift 操作符
RxSwift 操作符 (throttle) https://blog.csdn.net/weixin_38318852/article/details/80334838 RxSwift 操作符 (w ...