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 @@
# 练习 1Vue 实例和数据
## 目标
学会写一个最基础的 Vue2 实例,并让页面内容跟着数据变化。
## 你要练什么
- `new Vue()`
- `el`
- `data`
- `methods`
- 模板插值 `{{ }}`
## 任务
请基于页面结构完成以下操作:
- 显示课程标题和章节数量
- 点击按钮后让学习人数加 1
- 在控制台输出当前学习人数
## 文件
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/01-vue-instance-and-data/starter.html)
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/01-vue-instance-and-data/starter.js)
- [answer.html](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/01-vue-instance-and-data/answer.html)
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/01-vue-instance-and-data/answer.js)

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue 实例和数据</title>
<style>
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f5f7fb; }
.panel { max-width: 720px; margin: 0 auto; padding: 24px; border-radius: 18px; background: #fff; border: 1px solid #dce5f2; }
button { padding: 10px 16px; border: 0; border-radius: 999px; background: #2d6cdf; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="panel">
<h1>{{ title }}</h1>
<p>本章共有 {{ lessonCount }} 个小节。</p>
<p>当前学习人数:{{ learnerCount }}</p>
<button type="button" @click="increaseLearner">加入学习</button>
</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,14 @@
new Vue({
el: "#app",
data: {
title: "Vue2 基础入门",
lessonCount: 8,
learnerCount: 12,
},
methods: {
increaseLearner() {
this.learnerCount += 1;
console.log("当前学习人数:", this.learnerCount);
},
},
});

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vue 实例和数据</title>
<style>
body { margin: 0; padding: 32px; font-family: "PingFang SC", sans-serif; background: #f5f7fb; }
.panel { max-width: 720px; margin: 0 auto; padding: 24px; border-radius: 18px; background: #fff; border: 1px solid #dce5f2; }
button { padding: 10px 16px; border: 0; border-radius: 999px; background: #2d6cdf; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="panel">
<h1>{{ title }}</h1>
<p>本章共有 {{ lessonCount }} 个小节。</p>
<p>当前学习人数:{{ learnerCount }}</p>
<button type="button" @click="increaseLearner">加入学习</button>
</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,15 @@
new Vue({
el: "#app",
data: {
title: "Vue2 基础入门",
lessonCount: 8,
learnerCount: 12,
},
methods: {
increaseLearner() {
// 任务:
// 1. learnerCount 加 1
// 2. 在控制台输出最新人数
},
},
});