Vue-axios基础

可以直接使用代码引用

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

分为post和get请求

post请求

axios.post(api,{参数对象}).then{function(response){},function(err){}}

以官方文档为例:

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

 

get请求

axios.get(api?key=数值&key2=数值$...).then{function(response){},function(err){}}

以官方文档为例:

// 为给定 ID 的 user 创建请求
axios.get('/user?ID=12345')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

// 上面的请求也可以这样做
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

 

posted @ 2020-11-02 13:40  null_lii  阅读(61)  评论(0)    收藏  举报