Axios请求方式传递参数

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

axios.request(config)

//原始的Axios请求方式
axios({
  method: 'post',
  url: '/user/1111',
  data: {
    firstName: 'Dream',
    lastName: 'Green'
  },
  timeout: 1000,
  ...//其他相关配置
});

axios.get(url[, config])

axios.get('demo/url', {
    params: {
        id: 123,
        name: 'Green',
    },
   timeout: 1000,
  ...//其他相关配置
})

axios.delete(url[, config])

//如果服务端将参数作为java对象来封装接受
axios.delete('demo/url', {
    data: {
        id: 123,
        name: 'Green',
    },
     timeout: 1000,
    ...//其他相关配置
})
//如果服务端将参数作为url参数来接受,则请求的url为:www.demo/url?a=1&b=2形式
axios.delete('demo/url', {
    params: {
        id: 123,
        name: 'Green',
    },
     timeout: 1000,
    ...//其他相关配置
})

axios.post(url[, data[, config]])

axios.post('demo/url', {
    id: 123,
    name: 'Green',
},{
   timeout: 1000,
    ...//其他相关配置
})

axios.put(url[, data[, config]])

axios.put('demo/url', {
    id: 123,
    name: 'Green',
},{
   timeout: 1000,
    ...//其他相关配置
})

axios.patch(url[, data[, config]])

axios.patch('demo/url', {
    id: 123,
    name: 'Green',
},{
   timeout: 1000,
    ...//其他相关配置
})

猜你喜欢

转载自blog.csdn.net/weixin_51299408/article/details/120875985