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:
22
08-vue3/06-slots-and-provide-inject/README.md
Normal file
22
08-vue3/06-slots-and-provide-inject/README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# 练习 6:slot 与 provide / inject
|
||||
|
||||
## 目标
|
||||
|
||||
学会更灵活地组织组件树中的内容和共享信息。
|
||||
|
||||
## 你要练什么
|
||||
|
||||
- `slot`
|
||||
- `provide`
|
||||
- `inject`
|
||||
|
||||
## 任务
|
||||
|
||||
- 用插槽自定义卡片按钮文案
|
||||
- 父组件通过 `provide` 提供主题色
|
||||
- 子组件通过 `inject` 使用主题信息
|
||||
|
||||
## 文件
|
||||
|
||||
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/06-slots-and-provide-inject/starter.html)
|
||||
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/08-vue3/06-slots-and-provide-inject/starter.js)
|
||||
26
08-vue3/06-slots-and-provide-inject/starter.html
Normal file
26
08-vue3/06-slots-and-provide-inject/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>slot 与 provide/inject</title>
|
||||
<style>
|
||||
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f6f8fc; }
|
||||
.wrap { max-width: 820px; margin: 0 auto; }
|
||||
.card { padding: 20px; border-radius: 18px; background: #fff; border: 1px solid #dce5f2; }
|
||||
button { padding: 10px 14px; border: 0; border-radius: 999px; color: #fff; cursor: pointer; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section id="app" class="wrap">
|
||||
<theme-card>
|
||||
<template #default>
|
||||
继续学习
|
||||
</template>
|
||||
</theme-card>
|
||||
</section>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
|
||||
<script src="./starter.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
27
08-vue3/06-slots-and-provide-inject/starter.js
Normal file
27
08-vue3/06-slots-and-provide-inject/starter.js
Normal file
@@ -0,0 +1,27 @@
|
||||
const { createApp, provide, inject } = Vue;
|
||||
|
||||
createApp({
|
||||
components: {
|
||||
ThemeCard: {
|
||||
setup() {
|
||||
const themeColor = inject("themeColor");
|
||||
|
||||
return {
|
||||
themeColor,
|
||||
};
|
||||
},
|
||||
template: `
|
||||
<article class="card">
|
||||
<h2>主题卡片</h2>
|
||||
<button type="button" :style="{ background: themeColor }">
|
||||
<slot>默认按钮</slot>
|
||||
</button>
|
||||
</article>
|
||||
`,
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
// 任务:通过 provide 提供 themeColor
|
||||
return {};
|
||||
},
|
||||
}).mount("#app");
|
||||
Reference in New Issue
Block a user