如何获取fetch的值呢
使用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));
原文地址: https://www.cveoy.top/t/topic/Fpn 著作权归作者所有。请勿转载和采集!