我想问是否有人可以给我解释或检查这种情况下的javascript代码:
下面验证示例
`function Get() {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", `Bearer ${token.then((data)=>{data.access_token})}`);
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
};
const first = fetch("https://XXXXX", requestOptions)
const second = first.then(response => response.json())
return second;
}
console.log('Show data', data)`
提前感谢您的帮助!
结果是 - 非法返回语句。但我想我错过了从 API 中选择字段的部分代码。
function Get() {
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", `Bearer ${token.then((data)=>{data.access_token})}`);
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
const first = fetch("https://XXXXX", requestOptions)
const second = first.then(response => response.json())
return second;
}
let data = Get()
console.log('Show data', data)
也许您把大括号放错了,因此获取无法使用正确的标头,请尝试此代码