为了账号安全,请及时绑定邮箱和手机立即绑定

vue axios请求怎么获取 Response中的自定义headers

vue axios请求怎么获取 Response中的自定义headers

米琪卡哇伊 2019-03-19 21:19:08
vue axios请求怎么获取 Response中的自定义headers
查看完整描述

2 回答

?
zhhdiy

TA贡献1条经验 获得超1个赞

后端发送请求的时候设置:

// 自定义响应头

ctx.res.setHeader('myheader', 'abc')

// 通过此header设置允许前端访问

ctx.res.setHeader('Access-Control-Expose-Headers', 'myheader')

前端就可以获取了

response.headers['myheader']

查看完整回答
1 反对 回复 2019-12-21
  • qq_慕丝8258099
    qq_慕丝8258099
    应该说清楚一点: cors情况下,自定义请求头是需要设置暴露出来的,所以在服务端应该添加楼上的那句话 key:Access-Control-Expose-Headers val:(你自定义的header)
  • Dan_浅夏
    Dan_浅夏
    自定义的请求头内容是中文乱码。
?
慕田峪4524236

TA贡献1875条经验 获得超5个赞

{

  // `data` is the response that was provided by the server

  data: {},


  // `status` is the HTTP status code from the server response

  status: 200,


  // `statusText` is the HTTP status message from the server response

  statusText: 'OK',


  // `headers` the headers that the server responded with

  // All header names are lower cased

  headers: {},


  // `config` is the config that was provided to `axios` for the request

  config: {},


  // `request` is the request that generated this response

  // It is the last ClientRequest instance in node.js (in redirects)

  // and an XMLHttpRequest instance the browser

  request: {}

}

axios


查看完整回答
反对 回复 2019-04-05
  • 2 回答
  • 0 关注
  • 17947 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信