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

  1. vue 中使用 axios 请求接口,请求会发送两次问题

    在开发项目过程中,发现在使用axios调用接口都会有两个请求,第一个请求时,看不到请求参数,也看不到请求的结果:只有第二次请求时才会有相应的请求参数以及请求结果: 那为甚么会有这么一次额外的请求呢,后 ...

  2. vue中比较完美请求的栗子(使用 axios 访问 API)

    vue中比较完美请求的栗子(使用 axios 访问 API) 官网地址:https://vuejs.bootcss.com/v2/cookbook/using-axios-to-consume-api ...

  3. vue中采用axios发送请求及拦截器

    这几天在使用vue中axios发送get请求的时候很顺手,但是在发送post请求的时候老是在成功的回调函数里边返回参数不存在,当时就纳闷了,经过查阅资料,终于得到了解决方案,在此做一总结: 首先我们在 ...

  4. vue中使用axios与axios的请求响应拦截

    VUE中使用Axios axios的安装 npm install axios vue-axios axios在vue的配置与使用 在main.js中引入axios和vue-axios import a ...

  5. 介绍vue项目中的axios请求(get和post)

    一.先安装axios依赖,还有qs依赖 npm install axios --save npm install qs --save qs依赖包用post请求需要用到的 插入一个知识点: npm in ...

  6. vue中使用axios发送请求

    我们知道,vue2.0以后,vue就不再对vue-resource进行更新,而是推荐axios,而大型项目都会使用 Vuex 来管理数据,所以这篇博客将结合两者来发送请求 1.安装axios cnpm ...

  7. Vue中使用axios发送ajax请求

    作为前后端交互的重要技巧--发送ajax请求,在Vue中我们使用axio来完成这一需求: 首先是下载axios的依赖, npm install --save axios vue-axios 然后在ma ...

  8. vue中配置axios.js文件,发送请求

    为了统一管理请求,每个项目都会去配置axios:而不是在vue中直接使用,那样不好维护等等 下面是我配置的最基础的axios文件 第一步:首先新建一个axios文件,我是放在router文件下的 im ...

  9. Vue中发送ajax请求——axios使用详解

    axios 基于 Promise 的 HTTP 请求客户端,可同时在浏览器和 node.js 中使用 功能特性 在浏览器中发送 XMLHttpRequests 请求 在 node.js 中发送 htt ...

随机推荐

  1. python 中常见的异常类型汇总

    异常名称 描述 BaseException 所有异常的基类 SystemExit 解释器请求退出 KeyboardInterrupt 用户中断执行(通常是输入^C) Exception 常规错误的基类 ...

  2. XV6源代码阅读-文件系统

    Exercise1 源代码阅读 文件系统部分 buf.h fcntl.h stat.h fs.h file.h ide.c bio.c log.c fs.c file.c sysfile.c exec ...

  3. CI自带的文件上传及生成缩略图

    /* * 文件上传 * @param $upload_path 文件上传路径 * @param $formpic 表单name属性名称 */ private function doUpload($up ...

  4. java核心-多线程(8)- 并发原子类

        使用锁能解决并发时线程安全性,但锁的代价比较大,而且降低性能.有些时候可以使用原子类(juc-atomic包中的原子类).还有一些其他的非加锁式并发处理方式,我写这篇文章来源于Java中有哪些 ...

  5. 10 Class文件结构

  6. ②初识spring

    一:基础搭建 需要:eclipse.spring插件(确认版本号并下载对应插件详见:https://blog.csdn.net/a1150499208/article/details/87988392 ...

  7. 基于springboot实现Java阿里短信发送

    1.接口TestController import java.util.Random; import com.aliyuncs.DefaultAcsClient; import com.aliyunc ...

  8. jQuery通过name获取值

    使用jQuery获取name="day"的input对象: 方法1 var dayObj=$('input[name="day"]'); for(int i=0 ...

  9. web.xml中的classpath是啥

    在web.xml中一个很面熟的字:classpath,它到底是个啥? <servlet> <servlet-name>dispatcherServlet</servlet ...

  10. 076-PHP数组修改元素值

    <?php $arr=array(98,'hello',67,'A',85,NULL); //定义一个数组 echo '输出数组修改元素之前的详细信息:<br />'; print_ ...