vue中的axios请求
1、get请求
// get
this.$axios.get('请求路径')
.then(function (response) {
console.log(response); // 成功
})
.catch(function (error) {
console.log(error); // 失败
});
2、post请求
// post
this.$axios.post('请求路径', {
firstName: 'da',
lastName: 'xiong'
})
.then(function (response) {
console.log(response); / /成功
})
.catch(function (error) {
console.log(error); // 失败
});
3.或者在内部定义请求方式
this.$myAxios({
method: "post",//指定请求方式
url: "请求路径",
data: {
id:"123"
}
})
.then(function(response){
//接口成功返回结果执行
})
.catch(function(error){
//请求失败或者接口返回失败
})
4.实际应用的一个案例
this.$axios
.post(
this.domain + "/interfaceFsm/rest/job/queryDllConstant",
{
sysName: this.sysName,
key: "PRODUCT_ID_AUTO"
},
{
transformRequest: [
function(data) {
var str = "";
for (var key in data) {
str +=
encodeURIComponent(key) +
"=" +
encodeURIComponent(data[key]) +
"&";
}
return str;
}
]
}
)
.then(response => {
if ("0" == response.data.status) {
console.log("dllConstant", response.data);
}
})
.catch(function(error) {
alert(error);
});

vue中的axios请求的更多相关文章
- vue 中使用 axios 请求接口,请求会发送两次问题
在开发项目过程中,发现在使用axios调用接口都会有两个请求,第一个请求时,看不到请求参数,也看不到请求的结果:只有第二次请求时才会有相应的请求参数以及请求结果: 那为甚么会有这么一次额外的请求呢,后 ...
- vue中比较完美请求的栗子(使用 axios 访问 API)
vue中比较完美请求的栗子(使用 axios 访问 API) 官网地址:https://vuejs.bootcss.com/v2/cookbook/using-axios-to-consume-api ...
- vue中采用axios发送请求及拦截器
这几天在使用vue中axios发送get请求的时候很顺手,但是在发送post请求的时候老是在成功的回调函数里边返回参数不存在,当时就纳闷了,经过查阅资料,终于得到了解决方案,在此做一总结: 首先我们在 ...
- vue中使用axios与axios的请求响应拦截
VUE中使用Axios axios的安装 npm install axios vue-axios axios在vue的配置与使用 在main.js中引入axios和vue-axios import a ...
- 介绍vue项目中的axios请求(get和post)
一.先安装axios依赖,还有qs依赖 npm install axios --save npm install qs --save qs依赖包用post请求需要用到的 插入一个知识点: npm in ...
- vue中使用axios发送请求
我们知道,vue2.0以后,vue就不再对vue-resource进行更新,而是推荐axios,而大型项目都会使用 Vuex 来管理数据,所以这篇博客将结合两者来发送请求 1.安装axios cnpm ...
- Vue中使用axios发送ajax请求
作为前后端交互的重要技巧--发送ajax请求,在Vue中我们使用axio来完成这一需求: 首先是下载axios的依赖, npm install --save axios vue-axios 然后在ma ...
- vue中配置axios.js文件,发送请求
为了统一管理请求,每个项目都会去配置axios:而不是在vue中直接使用,那样不好维护等等 下面是我配置的最基础的axios文件 第一步:首先新建一个axios文件,我是放在router文件下的 im ...
- Vue中发送ajax请求——axios使用详解
axios 基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用 功能特性 在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 htt ...
随机推荐
- 2-10 就业课(2.0)-oozie:2、介绍和安装1
oozie的安装及使用 1. oozie的介绍 Oozie是运行在hadoop平台上的一种工作流调度引擎,它可以用来调度与管理hadoop任务,如,MapReduce.Pig等.那么,对于Oozie ...
- 021、Java中汉子与数字的相互转换,利用字符变量保存中文
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- 022、MySQL字符串的拼接
SELECT CONCAT('曾经沧海难为水-','-除却巫山不是云') #字符串拼接 SELECT CONCAT('AB','CD','EF'); #ABCDEF #字符串拼接 SELECT CON ...
- docker centos 镜像中安装python36详解!生成centos+python36的基础镜像
获取centos镜像docker pull centos:7.4.1708 启动并进入centos的容器docker run -i –t centos /bin/bash下载安装python编译环境依 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-chevron-right
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- 使用Hibarnate: 出现 java.sql.SQLException: ORA-00911: 无效字符, 解决思路
1. 查看到: Hibernat自动生成的sql查询语句 Hibernate: select * from ( select module0_.MODULE_ID as MODULE_ID1_1_, ...
- MongoDB_04_插入和查询
案列需求: 存在文章评论的数据存放到MongoDB中,数据结构参考如下: 数据库:articledb 专栏文章评论 comment / / 字段名称 字段含义 字段类型 备注 _id ID Objec ...
- REST接口
全名是Representational State Transfer REST是设计风格而不是标准 建议将JSON格式作为标准响应格式 -------------------------------- ...
- mybatis update set 多个字段
<update id="updateCustomer" parameterType="com.entrym.domain.Customer"> UP ...
- 064-PHP函数中局部变量在函数外不可使用
<?php function print_num(){ //定义函数 $x=6; //在函数中定义变量 } print_num(); //调用函数 echo $x; ?>