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,27 @@
# 练习 2模板语法和绑定
## 目标
学会把数据绑定到属性和事件上,而不是手动改 DOM。
## 你要练什么
- `{{ }}`
- `v-bind`
- `v-on`
- 事件方法
## 任务
请基于页面结构完成以下操作:
- 显示课程名和讲师名
- 绑定图片地址和课程链接
- 点击按钮后切换收藏状态
## 文件
- [starter.html](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/02-template-bindings/starter.html)
- [starter.js](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/02-template-bindings/starter.js)
- [answer.html](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/02-template-bindings/answer.html)
- [answer.js](/Users/lijiaqing/home/wwwroot/front-end-example/07-vue2/02-template-bindings/answer.js)

View File

@@ -0,0 +1,28 @@
<!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: #f6f8fb; }
.card { max-width: 680px; margin: 0 auto; padding: 24px; border-radius: 20px; background: #fff; border: 1px solid #dde6f5; }
img { width: 100%; border-radius: 16px; }
.link { display: inline-block; margin-top: 12px; color: #2d6cdf; }
button { margin-top: 18px; padding: 10px 16px; border: 0; border-radius: 999px; background: #15233f; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="card">
<h1>{{ courseTitle }}</h1>
<p>讲师:{{ teacher }}</p>
<img :src="coverUrl" :alt="courseTitle" />
<a class="link" :href="courseLink" target="_blank">查看课程详情</a>
<p>当前状态:{{ isCollected ? "已收藏" : "未收藏" }}</p>
<button type="button" @click="toggleCollect">切换收藏状态</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,16 @@
new Vue({
el: "#app",
data: {
courseTitle: "Vue2 模板语法",
teacher: "李老师",
coverUrl: "https://picsum.photos/800/320?random=21",
courseLink: "https://cn.vuejs.org/",
isCollected: false,
},
methods: {
toggleCollect() {
this.isCollected = !this.isCollected;
console.log("收藏状态:", this.isCollected ? "已收藏" : "未收藏");
},
},
});

View File

@@ -0,0 +1,28 @@
<!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: #f6f8fb; }
.card { max-width: 680px; margin: 0 auto; padding: 24px; border-radius: 20px; background: #fff; border: 1px solid #dde6f5; }
img { width: 100%; border-radius: 16px; }
.link { display: inline-block; margin-top: 12px; color: #2d6cdf; }
button { margin-top: 18px; padding: 10px 16px; border: 0; border-radius: 999px; background: #15233f; color: #fff; cursor: pointer; }
</style>
</head>
<body>
<section id="app" class="card">
<h1>{{ courseTitle }}</h1>
<p>讲师:{{ teacher }}</p>
<img :src="coverUrl" :alt="courseTitle" />
<a class="link" :href="courseLink" target="_blank">查看课程详情</a>
<p>当前状态:{{ isCollected ? "已收藏" : "未收藏" }}</p>
<button type="button" @click="toggleCollect">切换收藏状态</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,17 @@
new Vue({
el: "#app",
data: {
courseTitle: "Vue2 模板语法",
teacher: "李老师",
coverUrl: "https://picsum.photos/800/320?random=21",
courseLink: "https://cn.vuejs.org/",
isCollected: false,
},
methods: {
toggleCollect() {
// 任务:
// 1. 切换 isCollected
// 2. 在控制台输出最新收藏状态
},
},
});