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. (60)Wangdao.com第十天_JavaScript 函数_作用域_闭包_IIFE_回调函数_eval

    函数        实现特定功能的 n 条语句封装体. 1. 创建一个函数对象 var myFunc = new Function(); // typeof myFunc 将会打印 function ...

  2. ECMA Script 6_async 函数

    async 函数 const promise = new Promise((resolve, reject)=>{ setTimeout(function(){ console.log(&quo ...

  3. [LeetCode] Maximum Depth of N-ary Tree N叉树的最大深度

    Given a n-ary tree, find its maximum depth. The maximum depth is the number of nodes along the longe ...

  4. idea 常用快捷键

    =============intellij idea 快捷键============= ctrl+] 诸如{}围起来的代码块,使用该快捷键可以快速跳转至代码块的结尾处 ctrl+[ 同上,快速跳至代码 ...

  5. 白盒测试实践-day04

    一.任务进展情况 通过小组成员的共同努力,终于完成了此次“白盒测试实践”任务.目前的主要任务将之前的文件汇总,整理出来. 二.存在的问题 由于测试系统的不完善,导致单元测试比较麻烦. 三.解决方法 认 ...

  6. archlinux下我的软件列表

    编辑器:leafpad,gvim 终端:zsh,xfce4-terminal 音乐:网易云音乐(良心),DeadBeef(和win的foobar2000差不多) 视频播放:mpv PDF:Acrore ...

  7. 如何设置记事本( .txt文件)的默认编码为UTF-8?

    1.在桌面新建一个文本文档,不要写入任何内容,然后手动另存为,将此文档编码改为UTF-8,然后将文件名字改为template.txt: 2.再将template.txt移动到C:\Windows\Sh ...

  8. App拉起小程序提示跳转失败

    App拉起小程序提示跳转失败 req.userName = "gh_8afldfalsejw"; // 小程序的原始ID,注意不是Appid

  9. MFC全屏显示和多窗口动态显示的一些技巧和方法

    一.全屏 1.全屏窗口从dialogex继承,因为要处理一些东西 2.全屏代码,这样设置后尺寸不会出bug,只设置为最大值的话容易出bug //get current system resolutio ...

  10. react-native-Cocoapods-Swift-Project

    https://reactnative.cn/docs/integration-with-existing-apps/ 1.创建一个xcode工程,single View就行,项目语言选择swift, ...