Files
front-end-example/08-vue3/10-next-tick-and-component-v-model/starter.js
charlie d0d8be443b 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.
2026-03-24 23:02:58 +08:00

53 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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");