📜  如何使用异步等待获取 API 以获取数据,然后在 javascript 代码示例中捕获

📅  最后修改于: 2022-03-11 15:03:57.788000             🧑  作者: Mango

代码示例2
// how to Fetch API to Get Data using async await and then catch in javascript
async function getFetchData(url){
    await fetch(url)
    .then(response => response.json())
    .then(data => console.log(`Id: ${data[99].id}, Title: ${data[99].title}`))
    .catch(error => console.log(error))
}
getFetchData(apiUrl);