这是我的代码:
export async function fetchData(searchValue) {
await fetch(`https://api.edamam.com/search?q=${searchValue}&app_id=${apiId}&app_key=${apiKey}`)
.then(res => res.json())
.then(
(result) => {
return result;
},
(error) => {
return (`Error: ${error}`);
}
)
}
问题是:
我无法将结果返回给其他组件,但如果我将该值记录到控制台中,我可以看到该值,有什么帮助吗?
如果我返回"await fetch“语句,我可以通过控制台记录该对象,但我不知道如何访问数据you can see on this image
发布于 2020-07-15 02:53:07
像这样编写你的函数:
export async function fetchData() {
try {
const response = await fetch(
`https://api.edamam.com/search?q=${searchValue}&app_id=${apiId}&app_key=${apiKey}`
);
return await response.json();
} catch (err) {
console.log(`Error: ${error}`);
}
}
https://stackoverflow.com/questions/62901787
复制相似问题