以下代码片段给了我相同的结果。使用.then和async/await来获取数据有什么区别?
// Code 1
function fetchData() {
fetch(url)
.then(response => response.json())
.then(json => console.log(json))
}
// Code 2
async function fetchData() {
const response = await fetch(url);
const json = await response.json();
console.log(json);
}
Run Code Online (Sandbox Code Playgroud)