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/10-next-tick-and-component-v-model/README.md
Normal file
24
08-vue3/10-next-tick-and-component-v-model/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# 练习 10:nextTick 和组件 v-model
|
||||
|
||||
## 目标
|
||||
|
||||
学会在 DOM 更新完成后执行逻辑,并理解 Vue3 组件 `v-model` 的通信约定。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- `nextTick`
|
||||
- 组件 `v-model`
|
||||
- `modelValue`
|
||||
- `update:modelValue`
|
||||
|
||||
## 任务
|
||||
|
||||
- 封装一个搜索输入子组件
|
||||
- 父组件通过 `v-model` 绑定关键字
|
||||
- 点击“展开搜索区”后,等 DOM 更新完成再聚焦输入框
|
||||
- 在控制台输出关键字变化
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/10-next-tick-and-component-v-model/starter.html)
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/10-next-tick-and-component-v-model/starter.js)
|
||||
29
08-vue3/10-next-tick-and-component-v-model/starter.html
Normal file
29
08-vue3/10-next-tick-and-component-v-model/starter.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>nextTick 和组件 v-model</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f4f7fb; }
|
||||
.panel { max-width: 760px; margin: 0 auto; padding: 24px; border-radius: 18px; background: #fff; border: 1px solid #d9e4f1; }
|
||||
input, button { padding: 12px 14px; border-radius: 12px; font: inherit; }
|
||||
input { width: 100%; border: 1px solid #cad6e8; }
|
||||
button { border: 0; background: #2d6cdf; color: #fff; cursor: pointer; margin-bottom: 16px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section id="app" class="panel">
|
||||
<button type="button" @click="toggleSearch">展开搜索区</button>
|
||||
|
||||
<div v-if="showSearch">
|
||||
<search-input ref="searchBox" v-model="keyword"></search-input>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
52
08-vue3/10-next-tick-and-component-v-model/starter.js
Normal file
52
08-vue3/10-next-tick-and-component-v-model/starter.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const { createApp, ref, nextTick, watch } = Vue;
|
||||
|
||||
createApp({
|
||||
components: {
|
||||
SearchInput: {
|
||||
props: {
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
emits: ["update:modelValue"],
|
||||
template: `
|
||||
<input
|
||||
ref="inputEl"
|
||||
:value="modelValue"
|
||||
type="text"
|
||||
placeholder="请输入课程关键字"
|
||||
@input="$emit('update:modelValue', $event.target.value)"
|
||||
/>
|
||||
`,
|
||||
methods: {
|
||||
focus() {
|
||||
this.$refs.inputEl.focus();
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
const showSearch = ref(false);
|
||||
const keyword = ref("");
|
||||
const searchBox = ref(null);
|
||||
|
||||
watch(keyword, (newValue) => {
|
||||
// 任务:在控制台输出关键字变化
|
||||
});
|
||||
|
||||
async function toggleSearch() {
|
||||
// 任务:
|
||||
// 1. 切换 showSearch.value
|
||||
// 2. 如果展开了,await nextTick()
|
||||
// 3. 通过 searchBox.value.focus() 聚焦输入框
|
||||
}
|
||||
|
||||
return {
|
||||
showSearch,
|
||||
keyword,
|
||||
searchBox,
|
||||
toggleSearch,
|
||||
};
|
||||
},
|
||||
}).mount("#app");
|
||||
Reference in New Issue
Block a user