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:
23
08-vue3/03-watch-and-watch-effect/README.md
Normal file
23
08-vue3/03-watch-and-watch-effect/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 练习 3:watch 和 watchEffect
|
||||
|
||||
## 目标
|
||||
|
||||
学会区分“监听指定数据变化”和“自动收集依赖并执行副作用”。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- `watch`
|
||||
- `watchEffect`
|
||||
- 搜索关键字监听
|
||||
- 副作用日志
|
||||
|
||||
## 任务
|
||||
|
||||
- 输入关键字时,用 `watch` 输出变化日志
|
||||
- 用 `watchEffect` 输出当前筛选信息
|
||||
- 根据关键字过滤课程列表
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/03-watch-and-watch-effect/starter.html)
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/03-watch-and-watch-effect/starter.js)
|
||||
25
08-vue3/03-watch-and-watch-effect/starter.html
Normal file
25
08-vue3/03-watch-and-watch-effect/starter.html
Normal file
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>watch 和 watchEffect</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f7f9fd; }
|
||||
.panel { max-width: 760px; margin: 0 auto; padding: 24px; border-radius: 18px; background: #fff; border: 1px solid #d9e2f0; }
|
||||
input { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid #ccd7e9; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section id="app" class="panel">
|
||||
<h1>课程搜索</h1>
|
||||
<input v-model="keyword" type="text" placeholder="输入关键字" />
|
||||
<ul>
|
||||
<li v-for="item in filteredCourses" :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>
|
||||
30
08-vue3/03-watch-and-watch-effect/starter.js
Normal file
30
08-vue3/03-watch-and-watch-effect/starter.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const { createApp, ref, computed, watch, watchEffect } = Vue;
|
||||
|
||||
createApp({
|
||||
setup() {
|
||||
const keyword = ref("");
|
||||
const courses = ref([
|
||||
{ id: 1, title: "ref 和 reactive" },
|
||||
{ id: 2, title: "watch 和 watchEffect" },
|
||||
{ id: 3, title: "组件通信" },
|
||||
]);
|
||||
|
||||
const filteredCourses = computed(() => {
|
||||
// 任务:根据 keyword 过滤课程
|
||||
return courses.value;
|
||||
});
|
||||
|
||||
watch(keyword, (newValue, oldValue) => {
|
||||
// 任务:输出关键字变化日志
|
||||
});
|
||||
|
||||
watchEffect(() => {
|
||||
// 任务:输出当前筛选后的数量
|
||||
});
|
||||
|
||||
return {
|
||||
keyword,
|
||||
filteredCourses,
|
||||
};
|
||||
},
|
||||
}).mount("#app");
|
||||
Reference in New Issue
Block a user