feat: add Vue2 exercises for dynamic styles, lifecycle methods, component communication, and course management dashboard

- Implement dynamic styles and event handling in Vue2 with a card component.
- Create lifecycle methods exercise to simulate async data loading and instance destruction.
- Develop a component communication exercise with props, events, and slots.
- Build a comprehensive course management dashboard with filtering, statistics, and component interactions.
This commit is contained in:
charlie
2026-03-23 10:09:29 +08:00
parent 00d3c9e4c6
commit 3435848495
48 changed files with 1705 additions and 48 deletions

View File

@@ -0,0 +1,28 @@
# 练习 4条件渲染和列表渲染
## 目标
学会根据状态显示不同内容,并用 `v-for` 渲染一组数据。
## 你要练什么
- `v-if`
- `v-else`
- `v-show`
- `v-for`
- `:key`
## 任务
请基于页面结构完成以下操作:
- 切换“是否展开课程列表”
- 根据是否付费显示不同文案
-`v-for` 渲染课程数组
## 文件
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/04-conditional-and-list-rendering/starter.html)
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/04-conditional-and-list-rendering/starter.js)
- [answer.html](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/04-conditional-and-list-rendering/answer.html)
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/04-conditional-and-list-rendering/answer.js)

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>条件渲染和列表渲染</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 #dbe4f4; }
ul { padding-left: 18px; }
button { padding: 10px 16px; border: 0; border-radius: 999px; background: #2f6ee5; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="panel">
<h1>Vue2 渲染练习</h1>
<button type="button" @click="showList = !showList">切换课程列表</button>
<p v-if="isPaid">你已经开通会员课程。</p>
<p v-else>你还没有开通会员课程。</p>
<ul v-show="showList">
<li v-for="course in courses" :key="course.id">
{{ course.title }} - {{ course.status }}
</li>
</ul>
</section>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="./answer.js"></script>
</body>
</html>

View File

@@ -0,0 +1,12 @@
new Vue({
el: "#app",
data: {
isPaid: true,
showList: true,
courses: [
{ id: 1, title: "Vue 实例", status: "已完成" },
{ id: 2, title: "指令系统", status: "学习中" },
{ id: 3, title: "组件通信", status: "未开始" },
],
},
});

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>条件渲染和列表渲染</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 #dbe4f4; }
ul { padding-left: 18px; }
button { padding: 10px 16px; border: 0; border-radius: 999px; background: #2f6ee5; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="panel">
<h1>Vue2 渲染练习</h1>
<button type="button" @click="showList = !showList">切换课程列表</button>
<p v-if="isPaid">你已经开通会员课程。</p>
<p v-else>你还没有开通会员课程。</p>
<ul v-show="showList">
<li v-for="course in courses" :key="course.id">
{{ course.title }} - {{ course.status }}
</li>
</ul>
</section>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="./starter.js"></script>
</body>
</html>

View File

@@ -0,0 +1,12 @@
new Vue({
el: "#app",
data: {
isPaid: false,
showList: true,
courses: [
{ id: 1, title: "Vue 实例", status: "已完成" },
{ id: 2, title: "指令系统", status: "学习中" },
{ id: 3, title: "组件通信", status: "未开始" },
],
},
});