update
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user