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/04-lifecycle-and-template-ref/README.md
Normal file
23
08-vue3/04-lifecycle-and-template-ref/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# 练习 4:生命周期和模板 ref
|
||||
|
||||
## 目标
|
||||
|
||||
学会在组合式 API 里使用生命周期钩子,并通过模板 `ref` 获取 DOM。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- `onMounted`
|
||||
- `onUpdated`
|
||||
- `onUnmounted`
|
||||
- 模板 `ref`
|
||||
|
||||
## 任务
|
||||
|
||||
- 页面挂载后自动聚焦输入框
|
||||
- 数据更新后输出日志
|
||||
- 页面卸载前清理定时器
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/04-lifecycle-and-template-ref/starter.html)
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/04-lifecycle-and-template-ref/starter.js)
|
||||
23
08-vue3/04-lifecycle-and-template-ref/starter.html
Normal file
23
08-vue3/04-lifecycle-and-template-ref/starter.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>生命周期和模板 ref</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f4f8fb; }
|
||||
.panel { max-width: 720px; margin: 0 auto; padding: 24px; border-radius: 18px; background: #fff; border: 1px solid #d8e4f3; }
|
||||
input { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid #cad7ea; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section id="app" class="panel">
|
||||
<h1>生命周期练习</h1>
|
||||
<input ref="keywordInput" v-model="keyword" type="text" placeholder="页面挂载后请自动聚焦" />
|
||||
<p>当前输入:{{ keyword }}</p>
|
||||
</section>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
|
||||
<script src="./starter.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
28
08-vue3/04-lifecycle-and-template-ref/starter.js
Normal file
28
08-vue3/04-lifecycle-and-template-ref/starter.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { createApp, ref, onMounted, onUpdated, onUnmounted } = Vue;
|
||||
|
||||
createApp({
|
||||
setup() {
|
||||
const keyword = ref("");
|
||||
const keywordInput = ref(null);
|
||||
let timer = null;
|
||||
|
||||
onMounted(() => {
|
||||
// 任务:
|
||||
// 1. 让输入框自动聚焦
|
||||
// 2. 建立一个定时器
|
||||
});
|
||||
|
||||
onUpdated(() => {
|
||||
// 任务:输出 updated 日志
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
// 任务:清理定时器并输出销毁日志
|
||||
});
|
||||
|
||||
return {
|
||||
keyword,
|
||||
keywordInput,
|
||||
};
|
||||
},
|
||||
}).mount("#app");
|
||||
Reference in New Issue
Block a user