feat: Add Vue3 exercises and interview plan

- Introduced Vue3 exercises covering composable API, reactivity, lifecycle hooks, and built-in components.
- Added structured interview plan for frontend candidates focusing on HTML, CSS, JavaScript, TypeScript, and Vue.
- Included starter files for each exercise and detailed README documentation for guidance.
This commit is contained in:
charlie
2026-03-24 23:02:58 +08:00
parent 3435848495
commit d0d8be443b
41 changed files with 1551 additions and 5 deletions

View File

@@ -0,0 +1,26 @@
# 练习 7composable 和异步状态
## 目标
学会把可复用逻辑抽成 composable并管理 loading / error / data。
## 你要练什么
- composable
- `ref`
- 异步状态
- `loading`
- `error`
## 任务
- 把课程请求逻辑抽成 `useCourses`
- 页面加载时调用它
- 显示 loading
- 请求成功后渲染列表
- 请求失败时显示错误信息
## 文件
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/07-composable-and-async/starter.html)
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/07-composable-and-async/starter.js)

View File

@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>composable 和异步状态</title>
<style>
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f5f8fc; }
.panel { max-width: 760px; margin: 0 auto; padding: 24px; border-radius: 18px; background: #fff; border: 1px solid #dbe4f2; }
.error { color: #b42318; }
</style>
</head>
<body>
<section id="app" class="panel">
<h1>课程请求练习</h1>
<p v-if="loading">数据加载中...</p>
<p v-if="error" class="error">{{ error }}</p>
<ul v-if="!loading && !error">
<li v-for="item in courses" :key="item.id">{{ item.title }}</li>
</ul>
</section>
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
<script src="./starter.js"></script>
</body>
</html>

View File

@@ -0,0 +1,38 @@
const { createApp, ref, onMounted } = Vue;
function useCourses() {
const courses = ref([]);
const loading = ref(true);
const error = ref("");
async function loadCourses() {
// 任务:
// 1. 模拟异步请求
// 2. 成功时给 courses 赋值
// 3. 失败时给 error 赋值
// 4. 最后把 loading 设为 false
}
return {
courses,
loading,
error,
loadCourses,
};
}
createApp({
setup() {
const { courses, loading, error, loadCourses } = useCourses();
onMounted(() => {
// 任务:页面挂载后调用 loadCourses
});
return {
courses,
loading,
error,
};
},
}).mount("#app");