This commit is contained in:
rou
2026-03-23 14:56:04 +08:00
parent 00d3c9e4c6
commit 1071f4db05
27 changed files with 549 additions and 50 deletions

View File

@@ -16,3 +16,24 @@ function fakeFetchUser() {
// 3. 用 await 等待 fakeFetchUser()
// 4. 渲染用户信息
// 5. 用 try...catch 处理异常
const btn = document.getElementById("load-user-btn")
const status = document.getElementById("user-status")
const card = document.getElementById("user-card")
async function a() {
status.textContent = "加载中"
card.innerHTML = ""
try {
const a = await fakeFetchUser()
status.textContent = "加载成功"
card.innerHTML = `
<p>姓名:${a.name}</p>
<p>角色:${a.role}</p>
<p>任务:${a.focus}</p>
`
} catch (error) {
status.textContent = "加载失败"
}
}
btn.addEventListener("click", a)