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请求的更多相关文章

  1. Vue框架axios请求(类似于ajax请求)

    Vue框架axios get请求(类似于ajax请求) 首先介绍下,这个axios请求最明显的地方,通过这个请求进行提交的时候页面不会刷新 <!DOCTYPE html> <html ...

  2. nodejs-5.2 axios请求

    1.npm官方文档:https://www.npmjs.com/package/axios 2.axios:用于 浏览器 和 node.js的基于Promise的HTTP客户端 请求 特征 从浏览器制 ...

  3. 10. vue axios 请求未完成时路由跳转报错问题

    axios 请求未完成时路由跳转报错问题 前两天项目基本功能算是完成了,在公司测试时遇到了遇到了一个问题,那就是在请求未完成时进行路由跳转时会报错,想了几种办法来解决,例如加loading,请求拦截, ...

  4. axios请求本地的json文件在打包部署到子目录域名下,路径找不到

    前言: 因为要同时部署两个项目,有一个是部署到域名下面的子目录下,如:https://xxx.com/siot-admin vue 项目中使用axios请求了本地项目的static文件夹下的json文 ...

  5. 记录一次axios请求造成的数组初始化失败

    axios请求是一个异步的请求,简单来讲就是在做其他事情的时候可以把这个先放一边等其他的事情做完后再来做这件事件. 我之前这样调用了一个方法: mounted() { this.first() thi ...

  6. token回话保持,axios请求拦截和导航守卫以及token过期处理

    1:了解token:有时候大家又说token令牌.整个机制是前端第一次登陆发送请求,后端会根据前端的用户名和密码, 通过一些列的算法的到一个token令牌, 这个令牌是独一无二的,前端每次发送请求都需 ...

  7. 解决在vue中axios请求超时的问题

    查看更多精彩内容请访问我的新博客:https://www.cssge.com/ 自从使用Vue2之后,就使用官方推荐的axios的插件来调用API,在使用过程中,如果服务器或者网络不稳定掉包了, 你们 ...

  8. vue 路由拦截、axios请求拦截

    路由拦截 项目中,有些页面需要登录后才能进入,例如,在某页面A,用户在操作前需要先进入登录页(此时需要将上一页的地址(/survey/start)作为query存入login页面的地址中,如: htt ...

  9. vue中Axios请求豆瓣API数据并展示到Swipe中

    vue中Axios请求豆瓣API数据并展示到Swipe中 1.首先是安装Axios: 安装方法cnpm install axios --save 等待npm安装完毕: 2.在main.js中引入axi ...

  10. vue脚手架用axios请求本地数据

    首先需要声明的是:本地请求,不用考虑跨域问题,这适用刚入坑的前端小白看,小白在做自己的项目时,通常都是用自己写的json数据,之后用axios请求过来,渲染到页面上. 1.cnpm install a ...

随机推荐

  1. BOM 浏览器对象模型_不超过 4 KB 的 document.cookie 对象

    注意: 客户端储存应该使用 Web storage API 和 IndexedDB,不推荐使用 Cookie document.cookie 对象 是服务器保存在浏览器的一小段文本信息 用于读写当前网 ...

  2. laravel之数据库增删改查

  3. 19 ArcGIS Server 备份与恢复

    一.备份过程 1.找到已经安装的arcgis server安装目录,并找到备份工具: 2.快捷键win + R启动cmd,将备份工具文件拖入cmd窗口,enter 3. 通过backup.py脚本进行 ...

  4. python中的包与模块

    '''模块与模块之间的调用''' import first #调用整个变量 print(first.Index) # #调用函数 print(first.hello()) # per = first. ...

  5. C++ 编译发现 error C2146: syntax error : missing ';' before identifier 'm_ctrlserver'

    解决这个问题的根源是重复包含了头文件

  6. linux ---docker篇

    Docker docker是什么? docker最初是dotCloud公司创始人Solomom Hykes在法国期间发起的一个公司内部项目,它是基于dotCloud公司多年云服务技术的一次革新,并在2 ...

  7. 20175303 2018-2019-2 《Java程序设计》第8周学习总结

    20175303 2018-2019-2 <Java程序设计>第8周学习总结 教材学习内容总结 本周学习<Java程序设计>第十五章: 泛型: 泛型(Generics)的主要目 ...

  8. mayan游戏

    这道题超级好 就是我太菜了写了几个小时不算是debug了几个小时. 我只想出了几个小剪枝 可能是状态不太好吧 写完这道题真的是完美诠释了什么,叫做: 暴力出奇迹!!! 真的是太暴力了. 最多只移动5步 ...

  9. WinAPI 字符及字符串函数(9): lstrcat - 合并字符串

    unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...

  10. Python_tkinter(5)_GUI工具

    1.Excel行数统计工具 源代码 import xlrd import tkinter as tk import tkinter.filedialog # 计算一个工作簿中所有Sheet表的行数 d ...