【发布时间】:2020-02-28 10:13:13
【问题描述】:
我正在尝试解构我的 axios.get 请求的 response.headers,因为我只需要 x-csrf-token。它始终是第二个位置。这是 res.headers 响应的样子
{
'content-type': 'application/json; charset=utf-8',
'x-csrf-token': '17hoqAWEwVmcN32wYgN9WA==',
'cache-control': 'no-cache, no-store',
dataserviceversion: '2.0',
'c4c-odata-response-time': '1195 ms',
date: 'Fri, 28 Feb 2020 10:06:55 GMT',
'transfer-encoding': 'chunked',
connection: 'close, Transfer-Encoding',
'set-cookie': [
'sap-usercontext=sap-client=041; path=/;HttpOnly;Secure',
'
],
'strict-transport-security': 'max-age=31536000 ; includeSubDomains'
}
我试过了
let{a,b} = res.headers;
console.log(b);
和
let[,b] = res.headers;
console.log(b);
但我只是得到:未定义不是一个函数
【问题讨论】:
-
解构语法中的属性(即:a 和 b),需要是您的标头对象中的属性。你可以在这里阅读更多:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript get destructuring