【问题标题】:How do I add auth headers to axios hooks requests?如何将身份验证标头添加到 axios 挂钩请求?
【发布时间】:2020-03-24 09:03:00
【问题描述】:

我正在使用 React Hooks,我想使用 axios hooks 包将图像发送到 Cloudinary。

const [ 
    { data: putData, loading: putLoading, error: putError },
    executePut
  ] = useAxios(
    {
      url: 'https://api.myjson.com/bins/820fc',
      method: 'PUT'
    },
    { manual: true }
  )

文档对标头只字未提?

【问题讨论】:

    标签: axios react-hooks


    【解决方案1】:

    我相信你正在寻找这个:

    const [ 
        { data: putData, loading: putLoading, error: putError },
        executePut
      ] = useAxios(
        {
          url: 'https://api.myjson.com/bins/820fc',
          method: 'PUT',
          headers: {
            'Content-Type': 'application/json'
          }
        },
        { manual: true }
      )
    

    文档:https://github.com/axios/axios#request-config

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-02
      • 2020-12-18
      • 2020-02-13
      • 1970-01-01
      • 1970-01-01
      • 2021-11-19
      • 2018-07-30
      • 2021-12-05
      相关资源
      最近更新 更多