📜  尝试捕获异步等待 - Javascript 代码示例

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

代码示例4
async function getData() {
    try {
        const response = await fetch('https://jsonplaceholder.typicode.com/todos/1')
        const data = await response.json();
          const { userId, id, title, completed } = data;
          console.log(userId, id, title, completed);
    } catch(err) {
      alert(err)
    }
}
getData();