使用async/await方式获取fetch的值:

async function fetchData() {
  const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
  const data = await response.json();
  return data;
}

fetchData().then(data => {
  console.log(data);
});

使用Promise方式获取fetch的值:

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(data => console.log(data));
如何获取fetch的值呢

原文地址: https://www.cveoy.top/t/topic/Fpn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录