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:
26
08-vue3/13-script-setup-macros/README.md
Normal file
26
08-vue3/13-script-setup-macros/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# 练习 13:script setup、defineProps、defineEmits、defineExpose
|
||||
|
||||
## 目标
|
||||
|
||||
补上 Vue3 在工程化单文件组件里的核心宏语法。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- `<script setup>`
|
||||
- `defineProps`
|
||||
- `defineEmits`
|
||||
- `defineExpose`
|
||||
|
||||
## 说明
|
||||
|
||||
这一题不是浏览器 CDN 练习,而是单文件组件语法练习,需要放在 `Vite + Vue3` 之类的工程里使用。
|
||||
|
||||
## 任务
|
||||
|
||||
- 给子组件定义 `title` 和 `finished` 两个 props
|
||||
- 定义 `toggle` 事件并在按钮点击时触发
|
||||
- 暴露一个 `focusAction` 方法给父组件调用
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.vue](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/13-script-setup-macros/starter.vue)
|
||||
38
08-vue3/13-script-setup-macros/starter.vue
Normal file
38
08-vue3/13-script-setup-macros/starter.vue
Normal file
@@ -0,0 +1,38 @@
|
||||
<template>
|
||||
<article class="course-card">
|
||||
<h2>{{ title }}</h2>
|
||||
<p>{{ finished ? "已完成" : "学习中" }}</p>
|
||||
<button ref="actionButton" type="button" @click="handleToggle">
|
||||
切换状态
|
||||
</button>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from "vue";
|
||||
|
||||
// 任务:
|
||||
// 1. 用 defineProps 定义 title 和 finished
|
||||
// 2. 用 defineEmits 定义 toggle
|
||||
// 3. 点击按钮时触发 toggle
|
||||
// 4. 用 defineExpose 暴露 focusAction
|
||||
|
||||
const actionButton = ref(null);
|
||||
|
||||
function handleToggle() {
|
||||
// 在这里触发 emit
|
||||
}
|
||||
|
||||
function focusAction() {
|
||||
actionButton.value?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.course-card {
|
||||
padding: 18px;
|
||||
border-radius: 16px;
|
||||
border: 1px solid #dbe4f1;
|
||||
background: #fbfcfe;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user