这看起来应该非常简单和基本,但我无法从异步获取函数中获取数据。下面是我的代码。我们非常感谢您能深入了解我可能做错了什么。
const getData = async(url)=>{
try{
const response = await fetch(url);
const data = await response.json();
console.log(data) //<-- this is working
return data;
}
catch (error){
console.log(error);
}
}
const desiredData = getData(url);
console.log(desiredData) // <--this is empty