zoukankan      html  css  js  c++  java
  • axios请求写法

    发起一个GET请求

    // get传参数
    axios.get('/user?ID=12345')
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
    
    // get传参数        后端接收   req.query
    axios.get('/user', {
        params: {
          ID: 12345
        }

    }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });

    发起一个POST请求

    //post传参数
    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) {
        // Both requests are now complete
      }));

    axios 通用写法

    // 发送 POST 请求
    axios({
      method: 'post',
      url: '/user/12345',
      data: {
        firstName: 'Fred',
        lastName: 'Flintstone'
      }
    });
    //  GET 请求远程图片
    axios({
      method:'get',
      url:'http://bit.ly/2mTM3nY',
      responseType:'stream'
    })

    请求方法别名

    为了方便我们为所有支持的请求方法均提供了别名。

    axios.request(config)
    axios.get(url[, config])
    axios.delete(url[, config])
    axios.head(url[, config])
    axios.options(url[, config])
    axios.post(url[, data[, config]])
    axios.put(url[, data[, config]])
    axios.patch(url[, data[, config]])



    参考链接:https://www.jianshu.com/p/7a9fbcbb1114

  • 相关阅读:
    python基础---内置类型
    python基础---内置常量
    python基础---内置函数
    数据增强---CutMix
    数据增强---Mixup
    机器学习笔记---评估方法
    深度学习笔记-上溢和下溢
    线性代数笔记-子空间
    tensorflow2学习笔记---模块、层和模型
    tensorflow2学习笔记---Graph和tf.function
  • 原文地址:https://www.cnblogs.com/caoleyun/p/12767204.html
Copyright © 2011-2022 走看看