28 lines
663 B
JavaScript
28 lines
663 B
JavaScript
function loadConfig() {
|
|
return new Promise((resolve) => {
|
|
setTimeout(() => {
|
|
resolve({
|
|
title: "现代 JS 面板",
|
|
level: "进阶",
|
|
});
|
|
}, 800);
|
|
});
|
|
}
|
|
|
|
// 任务:
|
|
// 1. 写一个 async 函数
|
|
// 2. 用 await 等待 loadConfig()
|
|
// 3. 用 try...catch 处理流程
|
|
async function load() {
|
|
const status = document.getElementById("status")
|
|
status.textContent = "加载中"
|
|
try {
|
|
const a = await loadConfig()
|
|
status.textContent = "加载成功"
|
|
const output = document.getElementById("output")
|
|
output.textContent = JSON.stringify(a)
|
|
} catch (error) {
|
|
status.textContent = "加载失败"
|
|
}
|
|
}
|
|
load() |