查找获取 Mistake
找错误 中等
题目
这个函数做 不返回数据正确地. 查找 and fix mistake.
代码
async function getUser(id) {
const res = await fetch("/api/users/" + id);
const data = res.json();
return data;
}
提示
res.JSON() 返回 Promise — 它需要到 是 awaited.
解释
res.json() returns a Promise, not the parsed data directly. Without 'await', data is a pending Promise, not the actual JSON. The fix is: const data = await res.json();. The same applies to res.text() and res.blob().
相关资源
相关课程
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。