VUE中 axios GET和POST 如何使用

时间:2020-05-19 20:09:29   收藏:0   阅读:102

axios作用:Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。

  首先。安装及配置

    使用npm安装 

      npm install axios

    使用 yarn 安装

      yarn add axios

  然后在入口文件 main.js中引入

     import axios from ‘axios‘

     vue.prototype.$axios = axios

axios POST请求实例

      that.$axios.post(url,{a:1,b:2})
      .then(function (res) {
         console.log("返回值")
      })
      .catch(function (error) {
        console.log(error);
      });

 

axios get请求实例

       this.$axios.get(url,{params:{a:1,b:2}})
      .then(function (response) {
         console.log(‘返回值‘)
      })
      .catch(function (error) {
        //  this.$message.error(error);
      });

  

 

  

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!