feat: add TypeScript lessons and learning panel
- Introduced a new script to check TypeScript lesson files for errors. - Created a main TypeScript file to render lessons and their details. - Added lesson definitions with starter and answer codes. - Implemented a user interface for navigating and running lessons. - Styled the application with CSS for a better user experience. - Updated README to reflect the new TypeScript section and usage instructions.
This commit is contained in:
35
04-dom-events-async/09-async-await-panel/answer.js
Normal file
35
04-dom-events-async/09-async-await-panel/answer.js
Normal file
@@ -0,0 +1,35 @@
|
||||
function fakeFetchUser() {
|
||||
return new Promise(function (resolve) {
|
||||
setTimeout(function () {
|
||||
resolve({
|
||||
name: "林晨",
|
||||
role: "前端学习者",
|
||||
focus: "DOM + 事件 + 异步",
|
||||
});
|
||||
}, 900);
|
||||
});
|
||||
}
|
||||
|
||||
const loadButton = document.getElementById("load-user-btn");
|
||||
const statusText = document.getElementById("user-status");
|
||||
const userCard = document.getElementById("user-card");
|
||||
|
||||
async function loadUser() {
|
||||
statusText.textContent = "加载中...";
|
||||
userCard.innerHTML = "";
|
||||
|
||||
try {
|
||||
const user = await fakeFetchUser();
|
||||
|
||||
userCard.innerHTML = `
|
||||
<p>姓名:${user.name}</p>
|
||||
<p>身份:${user.role}</p>
|
||||
<p>当前重点:${user.focus}</p>
|
||||
`;
|
||||
statusText.textContent = "加载完成";
|
||||
} catch (error) {
|
||||
statusText.textContent = "加载失败";
|
||||
}
|
||||
}
|
||||
|
||||
loadButton.addEventListener("click", loadUser);
|
||||
Reference in New Issue
Block a user