[英]Javascript - Async await and fetch - return the value, not the promise?
[英]Javascript async await with Promise all and fetch returning [object promise]
有人可以向我解释为什么预期结果是[对象承诺]而不返回吗? 请帮帮我 :(
'class Conexao {
constructor(loading) {
this.loading = loading;
}
acessar(rota) {
return this.requisicao(rota, 1);
}
async requisicao(rota, id) {
let rotas = ['https://willianjusten.com.br/search.json']
rotas.push(rota);
await Promise.all(rotas.map(function(url) {
fetch(url).then(function(resp) {
return resp.json();
}).then(function(r) {
return r;
})
}));
}
}
let conn = new Conexao(true);
let result_final = conn.acessar('https://jsonplaceholder.typicode.com/posts/');
console.log(result_final);`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.