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:
24
08-vue3/09-reactivity-helpers/README.md
Normal file
24
08-vue3/09-reactivity-helpers/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# 练习 9:toRef、toRefs 和 readonly
|
||||
|
||||
## 目标
|
||||
|
||||
学会把响应式对象里的字段拆出来继续保持响应式,并理解只读数据的使用场景。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- `toRef`
|
||||
- `toRefs`
|
||||
- `readonly`
|
||||
|
||||
## 任务
|
||||
|
||||
- 用 `reactive` 管理学习者信息
|
||||
- 用 `toRef` 单独取出 `name`
|
||||
- 用 `toRefs` 拆出其余字段
|
||||
- 用 `readonly` 包一层设置项
|
||||
- 点击按钮更新学习者信息并观察页面变化
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/09-reactivity-helpers/starter.html)
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/09-reactivity-helpers/starter.js)
|
||||
26
08-vue3/09-reactivity-helpers/starter.html
Normal file
26
08-vue3/09-reactivity-helpers/starter.html
Normal 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>toRef、toRefs 和 readonly</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; }
|
||||
button { padding: 10px 16px; border: 0; border-radius: 999px; background: #2d6cdf; color: #fff; cursor: pointer; }
|
||||
code { background: #f2f6fb; padding: 2px 6px; border-radius: 8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section id="app" class="panel">
|
||||
<h1>{{ name }}</h1>
|
||||
<p>当前阶段:{{ stage }}</p>
|
||||
<p>学习天数:{{ studyDays }}</p>
|
||||
<p>主题模式:<code>{{ settings.theme }}</code></p>
|
||||
<button type="button" @click="updateProfile">更新资料</button>
|
||||
</section>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
|
||||
<script src="./starter.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
33
08-vue3/09-reactivity-helpers/starter.js
Normal file
33
08-vue3/09-reactivity-helpers/starter.js
Normal file
@@ -0,0 +1,33 @@
|
||||
const { createApp, reactive, toRef, toRefs, readonly } = Vue;
|
||||
|
||||
createApp({
|
||||
setup() {
|
||||
const profile = reactive({
|
||||
name: "林晨",
|
||||
stage: "Vue3 入门",
|
||||
studyDays: 12,
|
||||
});
|
||||
|
||||
const name = toRef(profile, "name");
|
||||
const { stage, studyDays } = toRefs(profile);
|
||||
const settings = readonly({
|
||||
theme: "light",
|
||||
});
|
||||
|
||||
function updateProfile() {
|
||||
// 任务:
|
||||
// 1. 更新 name.value
|
||||
// 2. 更新 stage.value
|
||||
// 3. 让 studyDays.value + 1
|
||||
// 4. 不要直接修改 settings.theme
|
||||
}
|
||||
|
||||
return {
|
||||
name,
|
||||
stage,
|
||||
studyDays,
|
||||
settings,
|
||||
updateProfile,
|
||||
};
|
||||
},
|
||||
}).mount("#app");
|
||||
Reference in New Issue
Block a user