我在Promise方面遇到麻烦了!
所以,我做了这个功能
async function getHashVisura(url,endpoint,token,myTypeVisura) {
const response = await fetch(url+endpoint,
{
method:"GET",
headers: {
'Authorization' : token,
}})
.then((response)=>{
return response.json()})
.then((response)=>{
let hash;
response.data.forEach((typeVisura)=>{
if (typeVisura.nome_visura===myTypeVisura) hash=typeVisura.hash_visura
})
return hash
});
console.log(response)
return response
}
然后我以这种方式调用此函数:
const HASHVISURACATASTALE =getHashVisura(URLOPENAPI,VISURE,TOKENOPENAPI,VISURACATASTALE);
很明显,如果我登录HASHVISURACATASTALE,他将还给我一个未完成的承诺。或者更确切地说,他所做的一切都会给我一个诺言。
日志中的[[PromiseResult]]是正确的,但是我不知道如何访问它。