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,22 @@
# 练习 5props 和 emit
## 目标
学会在 Vue3 里写基础组件通信。
## 你要练什么
- `props`
- `emit`
- 组件拆分
## 任务
- 把课程项拆成子组件
- 父组件传入课程对象
- 子组件点击按钮后通知父组件切换完成状态
## 文件
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/05-props-and-emits/starter.html)
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/05-props-and-emits/starter.js)

View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>props 和 emit</title>
<style>
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f4f7fb; }
.wrap { max-width: 820px; margin: 0 auto; display: grid; gap: 14px; }
.card { padding: 18px; border-radius: 16px; background: #fff; border: 1px solid #d9e3f2; }
.done { color: #1f8f54; }
button { padding: 10px 14px; border: 0; border-radius: 999px; background: #2d6cdf; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="wrap">
<course-item
v-for="course in courses"
:key="course.id"
:course="course"
@toggle="toggleCourse"
></course-item>
</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,39 @@
const { createApp } = Vue;
createApp({
components: {
CourseItem: {
props: {
course: {
type: Object,
required: true,
},
},
emits: ["toggle"],
template: `
<article class="card">
<h2>{{ course.title }}</h2>
<p :class="{ done: course.finished }">
{{ course.finished ? "已完成" : "学习中" }}
</p>
<button type="button" @click="$emit('toggle', course.id)">切换状态</button>
</article>
`,
},
},
setup() {
const courses = Vue.ref([
{ id: 1, title: "组合式 API", finished: true },
{ id: 2, title: "组件通信", finished: false },
]);
function toggleCourse(courseId) {
// 任务:根据 courseId 切换对应课程的 finished
}
return {
courses,
toggleCourse,
};
},
}).mount("#app");