刚遇到一个新问题,我的令牌被响应头从服务器传递为'x-auth'
似乎反应不能让我通过使用response.headers.x-auth访问此值,
如果我做console.log(response.headers)
,它确实显示
{content-type: "application/json; charset=utf-8", x-auth: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1Y…jE0fQ.vDdRlqqgmdhJgy9g20QnbZ6HVSkJv_ZXdeOdeAHwBhw"}
但是如果我使用console.log(response.headers.x-auth)
,它会得到'undefined',我的假设是它将x-auth视为x-auth而不是属性。
我该如何解决这个问题?谢谢!
您不能通过点表示法使用破折号访问对象的属性(因为破折号将被解释为减号),但您可以使用括号表示法来执行此操作:
response.headers['x-auth']