//异步请求 fetch().then().then()
// function getData(){
// fetch('https://jsonplaceholder.typicode.com/todos/')
// .then(response => response.json())
// .then(json => console.log(json))
// }
// 异步函数 async await
async function getData(){
//请求url
let url = 'https://jsonplaceholder.typicode.com/todos/'
// 等待请求的结果,在进行后面的操作
const response = await fetch(url);
//响应成功以后,将进行转为json处理
const res = await response.json();
console.log(res)
}
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!