` 元素,使用 `:style` 绑定为其设置背景颜色为“#f0f0f0”,字体大小为“16px”,字体颜色为“#333”。然后添加一个按钮,点击按钮后,将背景颜色改为“#ff0000”,字体大小改为“20px”,字体颜色改为“#fff”。
+
+ - 提示:可以使用对象形式的 `:style` 绑定,定义一个样式对象,在点击按钮时修改该对象的属性值。
+
+ ```vue
+
+
+
+
+
+
+
+
+
+
+
+ ```
+
+
+
+3. 数组形式的样式绑定
+ - 要求:页面上有一个图片元素 `
![]()
`,使用数组形式的 `:style` 绑定为其设置宽度为“200px”,高度为“200px”。然后添加两个按钮,一个按钮点击后将图片的宽度和高度都扩大到“300px”,另一个按钮点击后将图片的宽度和高度恢复到“200px”。
+
+ - 提示:数组中可以包含多个样式对象,通过修改数组中的对象来实现样式的动态变化。
+
+ ```vue
+
+
+
+
+
+
+
+
+
+
+ ```
+
+
+
+## 七、事件处理
+
+### 基础题
+
+1. **按钮点击事件**
+
+ - **题目描述**:创建一个简单的 Vue 3 应用,页面上有一个按钮,当点击按钮时,页面上显示“按钮被点击了”。
+
+ ```vue
+
+
+
+
+
+ ```
+
+
+
+2. **输入框输入事件**
+
+ - **题目描述**:创建一个 Vue 3 应用,页面上有一个输入框,当用户在输入框中输入内容时,页面上实时显示输入的内容。
+
+ ```vue
+
+
+
+
+
+ ```
+
+
+
+### 中等题
+
+1. **表单提交事件**
+
+ - **题目描述**:创建一个 Vue 3 应用,页面有一个上表单,表单中有用户名和密码输入框,当点击提交按钮时,验证用户名和密码是否为空,如果为空,则在页面上显示相应的提示信息。
+
+ ```vue
+
+
+
+
+
+ ```
+
+
+
+2. **鼠标事件**
+
+ - **题目描述**:创建一个 Vue 3 应用,页面上有一个按钮,当鼠标移入按钮时,按钮的背景颜色变为红色,当鼠标移出按钮时,按钮的背景颜色恢复为默认颜色。
+
+ ```vue
+
+
+
+
+
+
+
+
+
+ ```
+
+
+
+### 拓展题
+
+1. 事件修饰符和键盘事件
+
+ - **题目描述**:创建一个 Vue 3 应用,页面上有一个输入框,当用户按下回车键时,页面上显示输入的内容,并清空输入框。
+
+ ```vue
+
+
+
+
+
+
+
+ ```
+
+
+
+## 九、侦听器
+
+### 基础练习
+
+1. **监听简单数据变化**:
+
+ - 要求:创建一个简单的 Vue3 应用,页面上有一个按钮和一个显示数字的文本。点击按钮使数字加1,使用侦听器监听该数字的变化,当数字变化时在控制台打印新值和旧值。
+ - 参考效果如下:
+
+ 
+
+```vue
+
+
+
+
当前数值:{{number}}
+
+
+
+
+
+```
+
+2.**监听对象属性变化**:
+
+- 要求:创建一个包含姓名和年龄的对象,通过输入框分别修改姓名和年龄,使用侦听器分别监听姓名和年龄的变化,并在控制台打印变化信息。
+- 参考效果如下:
+
+
+
+```vue
+
+
+
+
+
+
+
+
+
+```
+
+### 进阶练习
+
+1. 1. **深度监听对象变化**:
+
+ - 要求:创建一个包含多个属性的对象,如商品信息对象,包含价格、数量等属性。通过输入框修改这些属性的值,使用侦听器深度监听该对象的变化,当对象内部属性发生变化时在控制台打印变化信息。
+ - 参考效果如下:
+
+ 
+
+ ```vue
+
+
+
+
+
+
+
+
+
+ ```
+
+
+
+2. **使用 immediate 选项**:
+
+ - 要求:创建一个计数器应用,页面上有一个按钮和一个显示计数器数值的文本。点击按钮使计数器加1,使用侦听器监听计数器数值的变化,并在控制台打印新值和旧值。同时,要求在组件创建时立即执行一次侦听器的回调函数,打印初始值。
+ - 参考效果如下:
+
+ 
+
+```vue
+
+
+
+
{{ number }}
+
+
+
+
+
+```
+
+### 综合练习
+
+1. **监听数组变化并更新视图**:
+
+ - 要求:创建一个包含多个任务的数组,每个任务包含任务名称和是否完成的布尔值。页面上显示任务列表,每个任务旁边有复选框用于标记任务是否完成。使用侦听器监听任务数组的变化,当任务的完成状态发生变化时,更新页面上任务的显示样式(如已完成的任务显示为灰色)。
+ - 参考效果如下:
+
+ 
+
+```vue
+
+
+ 任务1
+ 任务2
+ 任务3
+
+
+
+
+
+```
+
+## 十一、组件基础
+
+### 基础练习
+
+#### 1. 定义和使用简单组件
+
+- **要求**:创建一个简单的组件 `HelloWorld`,该组件显示一个欢迎信息(如“Hello, Vue3!”)。在父组件中引入并使用该组件。
+
+ ```vue
+
+
+
+
+
+
+
+
+
+
+ ```
+
+
+
+#### 传递属性(Props)
+
+- **要求**:扩展 `HelloWorld` 组件,使其能够通过 `props` 接收一个名字,并显示欢迎信息(如“Hello, [名字]!”)。在父组件中传递不同的名字。
+- **参考效果如下**:
+
+
+
+```vue
+//HelloWorld.vue
+
+
+
{{Message}}
+
+
+
+
+```
+
+```vue
+// App.vue
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+### 进阶练习
+
+#### 3. 自定义事件
+
+- **要求**:创建一个 `ButtonCounter` 组件,该组件包含一个按钮和一个计数器。每次点击按钮时,计数器加1,并通过自定义事件将当前计数值传递给父组件。
+- **参考效果如下**:
+
+
+
+```vue
+// ButtonCounter
+
+
+
+
+
+
+
+```
+
+```vue
+// app.vue
+
+
+
+ 按钮计数器示例{{item}}
+
+
+```
+
+#### 4. 使用插槽(Slots)
+
+- **要求**:创建一个 `Card` 组件,该组件包含一个标题和一个内容区域。通过插槽允许父组件自定义标题和内容。
+- **参考效果如下**:
+
+
+
+```vue
+//Card.vue
+
+
+
+
+ 123456
+ 789789
+
+
+
+
+```
+
+```vue
+// App.vue
+
+
+
+ 自定义标题
+
+
+
+ 自定义标题
+
+
+
+
+
+```
+
+### 综合练习
+
+#### 5. 组件组合与数据传递
+
+- **要求**:创建一个 `UserProfile` 组件,该组件包含用户的基本信息(如用户名、邮箱)和一个按钮。点击按钮时,通过自定义事件将用户信息传递给父组件。父组件接收用户信息并显示在页面上。
+- **参考效果如下**:
+
+
+
+ ```vue
+ //UserProfile.vue
+
+
+
+
+
+ 用户信息
+ 用户名: {{ user.username }}
+ 邮箱: {{ user.email }}
+
+
+
+
+ ```
+
+```vue
+//app.vue
+
+
+
+
+
+```
+
+
+
+#### 6. 动态组件与条件渲染
+
+- **要求**:创建一个 `Tab` 组件,允许用户切换不同的标签页。每个标签页显示不同的内容。通过动态组件和条件渲染实现标签页的切换。
+- **参考效果如下**:
+
+
+
+```vue
+
+
+
+
+
+
+```
+
+```vue
+
+ Home
+ 欢迎来到首页
+
+```
+
+```vue
+
+ Profile
+ 用户资料页面
+
+```
+
+```vue
+
+ Settings
+ 设置页面
+
+```
+
+
+
+## 十二、路由
+
+### 基础练习题
+
+1. **创建基本路由**
+
+ - 使用 Vue 3 和 Vue Router 创建一个简单的单页面应用,包含两个页面:`Home` 和 `About`。
+ - 要求:
+ - 使用 `vue-router` 的最新版本。
+ - 在 `Home` 页面显示“欢迎来到首页!”的文本。
+ - 在 `About` 页面显示“这是关于页面!”的文本。
+ - 使用 `
` 实现页面之间的导航。
+ - 提示:参考 Vue Router 的基本安装和配置方法。
+
+ ```vue
+
+
+ home
+ About
+
+
+
+
+
+
+ ```
+
+ ```js
+ import { createRouter, createWebHistory } from 'vue-router'
+
+
+ const router = createRouter({
+ history: createWebHistory(import.meta.env.BASE_URL),
+ routes: [
+ {
+ path: '/',
+ name: 'home',
+ component: ()=>import('@/components/Home.vue'),
+ },
+ {
+ path: '/about',
+ name: 'about',
+ // route level code-splitting
+ // this generates a separate chunk (About.[hash].js) for this route
+ // which is lazy-loaded when the route is visited.
+ component: () => import('@/components/About.vue'),
+ },
+ ],
+ })
+
+ export default router
+
+ ```
+
+
+
+2. **动态路由匹配**
+
+ - 在上述基础上,添加一个动态路由 `/user/:id`,用于显示用户信息。
+
+ - 要求:
+
+ - 创建一个名为 `User` 的组件。
+ - 在 `User` 组件中,通过 `$route.params.id` 获取动态参数,并在页面上显示“用户ID为:[id]”。
+ - 在 `Home` 页面添加一个按钮,点击后跳转到 `/user/123`。
+
+ - 提示:动态路由的定义格式为 `path: '/user/:id'`。
+
+ ```vue
+
+ 首页
+
+
+
+
+ //Home.vue
+ ```
+
+ ```vue
+
+
+
+ 用户 ID 为:{{ userId }}
+
+
+
+
+
+ ```
+
+ ```vue
+
+
+
+
+ ```
+
+
+
+3. **嵌套路由**
+
+ - 在 `About` 页面中添加两个子页面:`About/Team` 和 `About/History`。
+
+ - 要求:
+
+ - 在 `About` 组件中使用 `` 渲染子页面。
+ - 在 `About/Team` 页面显示“这是团队页面!”。
+ - 在 `About/History` 页面显示“这是历史页面!”。
+ - 在 `About` 页面添加两个链接,分别跳转到 `About/Team` 和 `About/History`。
+
+ - 提示:嵌套路由的配置需要在父路由的 `children` 属性中定义子路由。
+
+ ```vue
+
+ 团队介绍
+ 发展历史
+
+
+
+
+
+
+ ```
+
+ ```js
+ import { createRouter, createWebHistory } from 'vue-router'
+
+
+ const router = createRouter({
+ history: createWebHistory(import.meta.env.BASE_URL),
+ routes: [
+ {
+ path: '/',
+ name: 'home',
+ component: ()=>import('@/components/Home.vue'),
+ },
+ {
+ path: '/about',
+ name: 'about',
+ component: () => import('@/components/About.vue'),
+ children: [
+ {
+ path: 'team',
+ component:()=>import('@/components/Team.vue')
+ },
+ {
+ path: 'history',
+ component:()=>import('@/components/History.vue')
+ }
+ ]
+ },
+ {
+ path:'/user/:id',
+ component:()=>import('@/components/User.vue')
+ }
+ ],
+ })
+
+ export default router
+
+ ```
+
+ ```vue
+
+ 这是团队页面!
+ 团队成员信息...
+
+ ```
+
+ ```vue
+
+ 这是历史页面!
+ 公司发展历程...
+
+ ```
+
+
+
+### 中级练习题
+
+4. **路由守卫(全局守卫)**
+
+ - 在项目中添加全局路由守卫,实现以下功能:
+
+ - 当用户访问 `/about` 页面时,弹出一个确认框,询问用户是否继续。
+ - 如果用户点击“确定”,则允许访问;如果点击“取消”,则取消导航。
+
+ - 要求:
+
+ - 使用 `router.beforeEach` 全局前置守卫。
+ - 在确认框中显示“确定要访问关于页面吗?”。
+
+ - 提示:全局前置守卫的回调函数参数为 `(to, from, next)`,其中 `next` 用于控制导航是否继续。
+
+ ```js
+ // src/router/index.js (在路由实例创建后添加守卫)
+ import { createRouter } from 'vue-router'
+
+ const router = createRouter({ /*...路由配置...*/ })
+
+ // 全局前置守卫
+ router.beforeEach((to, from, next) => {
+ if (to.path === '/about') {
+ const answer = window.confirm('确定要访问关于页面吗?')
+ answer ? next() : next(false)
+ } else {
+ next() // 确保其他路径通行
+ }
+ })
+
+ export default router
+
+ ```
+
+
+
+5. **路由守卫(组件内守卫)**
+
+ - 在 `User` 组件中添加组件内路由守卫,实现以下功能:
+
+ - 当用户离开 `User` 页面时,弹出一个提示框,显示“您正在离开用户页面!”。
+
+ - 要求:
+
+ - 使用组件内的 `beforeRouteLeave` 守卫。
+ - 在提示框中显示指定内容。
+
+ - 提示:组件内守卫可以直接在组件的 `beforeRouteLeave` 钩子中实现。
+
+ ```vue
+
+ 用户 ID 为:{{ userId }}
+
+
+
+
+
+ //User.vue
+
+ ```
+
+ ```vue
+ //Home.vue
+
+ 首页
+
+
+
+
+ ```
+
+
+
+6. **路由元信息(Meta Fields)**
+
+ - 在路由配置中为 `Home` 和 `About` 页面添加元信息,分别设置标题为“首页”和“关于”。
+
+ - 要求:
+
+ - 在路由定义中使用 `meta` 属性,例如:
+
+ ```javascript
+ {
+ path: '/home',
+ component: Home,
+ meta: { title: '首页' }
+ }
+ ```
+
+ - 在全局导航守卫中,根据当前路由的 `meta.title` 动态设置页面标题。
+
+ - 提示:可以通过 `document.title` 设置页面标题。
+
+ ```js
+ // src/router/index.js
+ const routes = [
+ {
+ path: '/',
+ name: 'Home',
+ component: () => import('@/views/Home.vue'),
+ meta: {
+ title: '首页' // 元数据声明
+ }
+ },
+ {
+ path: '/about',
+ name: 'About',
+ component: () => import('@/views/About.vue'),
+ meta: {
+ title: '关于我们'
+ },
+ children: [
+ // 嵌套子路由配置
+ ]
+ }
+ ]
+ // 在路由实例中添加全局守卫
+ router.beforeEach((to) => {
+ // 获取最深层的有效标题(支持嵌套路由)
+ const activeRoute = to.matched
+ .slice() // 克隆数组避免修改原数据
+ .reverse() // 从深层路由开始查找
+ .find(r => r.meta?.title)
+
+ document.title = activeRoute?.meta.title || '默认标题'
+ })
+
+ ```
+
+
+
+
+
+### 高级练习题
+
+7. **路由懒加载**
+
+ - 对项目中的路由组件进行懒加载优化,以减少初始加载时间。
+
+ - 要求:
+
+ - 使用 ES6 的动态导入语法(`import()`)对 `Home`、`About` 和 `User` 组件进行懒加载。
+ - 确保懒加载的组件在首次访问时才加载。
+
+ - 提示:懒加载的路由配置示例:
+
+ ```javascript
+ {
+ path: '/home',
+ component: () => import('./views/Home.vue')
+ }
+ ```
+
+ ```js
+ // 导出Vue路由模块
+ export const routes = [
+ {
+ path: "/User",
+ component: () => import("@/components/User.vue"),
+ },
+ {
+ path: "/Home",
+ component: () => import("@/components/Home.vue"),
+ },
+ {
+ path: "/About",
+ component: () => import("@/components/About.vue"),
+ },
+ ];
+ ```
+
+
+
+8. **自定义路由滚动行为**
+
+ - 在项目中实现自定义路由滚动行为,当用户在不同页面之间切换时,页面滚动到顶部。
+
+ - 要求:
+
+ - 使用 Vue Router 提供的 `scrollBehavior` 配置。
+ - 当用户从一个页面跳转到另一个页面时,页面自动滚动到顶部。
+
+ - 提示:`scrollBehavior` 的配置示例:
+
+ ```javascript
+ const router = createRouter({
+ history: createWebHistory(),
+ routes: [...],
+ scrollBehavior(to, from, savedPosition) {
+ return { top: 0 };
+ }
+ });
+ ```
+
+ ```js
+ // 导入依赖包
+ import { createRouter, createWebHistory } from "vue-router";
+
+ // 导入Vue路由模块
+ import { routes } from "@/routes";
+
+ // 创建并导出实例
+ export const router = createRouter({
+ history: createWebHistory(),
+ routes,
+ scrollBehavior(to, from, savedPosition) {
+ return { top: 10 };
+ },
+ });
+ ```
+
+ ```js
+ // 导出Vue路由模块
+ export const routes = [
+ {
+ path: "/User",
+ component: () => import("@/components/User.vue"),
+ },
+ {
+ path: "/Home",
+ component: () => import("@/components/Home.vue"),
+ },
+ {
+ path: "/About",
+ component: () => import("@/components/About.vue"),
+ },
+ ];
+ ```
+
+
+
+9. **多视图路由**
+
+ - 在项目中实现多视图路由,创建一个布局页面 `Layout`,并在其中包含两个视图:
+
+ - 一个用于显示主内容(`Home` 和 `About` 页面)。
+ - 一个用于显示侧边栏(`Sidebar` 组件)。
+
+ - 要求:
+
+ - 在 `Layout` 组件中使用两个 ``,分别绑定到不同的命名视图。
+ - 在路由配置中,为 `Home` 和 `About` 页面指定主内容视图,为 `Sidebar` 组件指定侧边栏视图。
+
+ - 提示:命名视图的配置示例:
+
+ ```javascript
+ {
+ path: '/home',
+ components: {
+ default: Home,
+ sidebar: Sidebar
+ }
+ }
+ ```
+
+ ```js
+ import Sidebar from "@/components/Sidebar.vue";
+
+ // 导出Vue路由模块
+ export const routes = [
+ {
+ path: "/Layout",
+ component: () => import("@/components/Layout.vue"),
+ children: [
+ {
+ path: "/Home",
+ components: {
+ default: () => import("@/components/Home.vue"),
+ Sidebar: () => import("@/components/Sidebar.vue"),
+ },
+ },
+ {
+ path: "/About",
+ components: {
+ default: () => import("@/components/About.vue"),
+ Sidebar: () => import("@/components/Sidebar.vue"),
+ },
+ },
+ ],
+ },
+ ];
+ ```
+
+ ```vue
+
+
+ Home
+ About
+
+
+
+
+
+
+ ```
+
+
+
+## 十三、嵌套路由
+
+### 基础题目
+
+#### 题目1:实现简单的嵌套路由
+
+**任务描述**:创建一个 Vue 3 项目,包含一个父路由和两个子路由。父路由的路径为 `/parent`,子路由分别为 `/child1` 和 `/child2`。父路由组件中显示一个导航栏,点击导航栏的链接可以切换到对应的子路由组件。
+
+**要求**:
+
+1. 使用 Vue Router 4 配置嵌套路由。
+2. 父路由组件中显示一个导航栏,导航栏包含两个链接,分别指向 `/parent/child1` 和 `/parent/child2`。
+3. 子路由组件中分别显示不同的内容。
+
+**提示**:
+
+- 在路由配置中定义嵌套路由。
+- 使用 `` 实现导航链接。
+- 使用 `` 显示子路由组件。
+
+```vue
+
+
+
+ 子路由1
+ 子路由2
+
+
+
+
+
+
+
+
+```
+
+```js
+// 导出Vue路由模块
+export const routes = [
+ {
+ path: '/parent',
+ // component: () => import('@/components/Home.vue'),
+ children: [
+ {
+ path: '/child1',
+ component: () => import('@/components/Child1.vue'),
+ },
+ {
+ path: '/child2',
+ component: () => import('@/components/Child2.vue'),
+ }
+ ],
+ },
+]
+```
+
+
+
+#### 题目2:动态嵌套路由
+
+**任务描述**:在上一题的基础上,将子路由的路径改为动态路径,例如 `/parent/:id`,并通过路由参数传递数据。
+
+**要求**:
+
+1. 修改路由配置,将子路由路径改为动态路径。
+2. 在父路由组件中添加一个输入框,用户输入的值作为子路由的参数。
+3. 在子路由组件中显示传递的参数。
+
+**提示**:
+
+- 使用动态路由匹配。
+- 在子路由组件中通过 `this.$route.params` 获取参数。
+
+```vue
+
+
+
+
+
+```
+
+```js
+// 导出Vue路由模块
+export const routes = [
+ {
+ path: '/parent',
+ // component: () => import('@/components/Home.vue'),
+ children: [
+ {
+ path: '/child1/:id?',
+ component: () => import('@/components/Child1.vue'),
+ },
+ {
+ path: '/child2',
+ component: () => import('@/components/Child2.vue'),
+ }
+ ],
+ },
+]
+```
+
+
+
+### 中等难度题目
+
+#### 题目3:嵌套路由的多级嵌套
+
+**任务描述**:创建一个包含三级嵌套路由的项目。父路由路径为 `/parent`,子路由路径为 `/child`,孙子路由路径为 `/grandchild`。每个层级的组件都显示不同的内容,并提供导航链接。
+
+**要求**:
+
+1. 配置三级嵌套路由。
+2. 在父路由组件中提供导航到子路由的链接。
+3. 在子路由组件中提供导航到孙子路由的链接。
+4. 在孙子路由组件中显示内容。
+
+**提示**:
+
+- 使用多级嵌套路由配置。
+- 在每个层级的组件中使用 `` 显示子组件。
+
+```vue
+
+
+
+
+
+
+```
+
+```vue
+
+ child的内容
+
+
+
+
+```
+
+
+
+```js
+// 导出Vue路由模块
+export const routes = [
+ {
+ path: '/parent',
+ children: [
+ {
+ path: '/child',
+ component: () => import('@/components/Child.vue'),
+ children: [
+ {
+ path: '/grandchild',
+ component: () => import('@/components/Grandchild.vue'),
+ }
+ ]
+ }
+ ],
+ },
+]
+```
+
+
+
+#### 题目4:嵌套路由的参数传递与默认值
+
+**任务描述**:在嵌套路由中,子路由和孙子路由都需要接收参数。如果参数未传递,则显示默认值。
+
+**要求**:
+
+1. 修改上一题的路由配置,为子路由和孙子路由添加动态参数。
+2. 在子路由和孙子路由组件中,如果参数未传递,则显示默认值。
+3. 在父路由组件中提供导航链接,用户可以选择是否传递参数。
+
+**提示**:
+
+- 使用动态路由匹配。
+- 在组件中通过 `this.$route.params` 获取参数,并设置默认值。
+
+```vue
+
+
+
+
+
+```
+
+```vue
+
+ child的内容
+ {{ $route.params.id1 ? $route.params.id1 : "未传递参数" }}
+
+
+
+
+```
+
+```vue
+
+ grandchild的内容
+ {{ $route.params.id2 ? $route.params.id2 : "未传递参数" }}
+
+```
+
+```js
+// 导出Vue路由模块
+export const routes = [
+ {
+ path: '/parent',
+ children: [
+ {
+ path: '/child/:id1?',
+ component: () => import('@/components/Child.vue'),
+ children: [
+ {
+ path: '/grandchild/:id2?',
+ component: () => import('@/components/Grandchild.vue'),
+ }
+ ]
+ }
+ ],
+ },
+]
+```
+
+
+
+### 高级题目
+
+#### 题目5:嵌套路由的懒加载与代码分割
+
+**任务描述**:在嵌套路由中,使用懒加载和代码分割优化项目性能。每个路由组件按需加载,减少初始加载时间。
+
+**要求**:
+
+1. 修改路由配置,使用懒加载加载每个路由组件。
+2. 在父路由组件中提供导航链接,点击链接时按需加载对应的子路由组件。
+3. 使用 Vue Router 的 `async` 组件实现懒加载。
+
+**提示**:
+
+- 使用 `() => import()` 语法实现懒加载。
+- 确保每个路由组件按需加载。
+
+```vue
+
+
+
+
+
+```
+
+```js
+// 导出Vue路由模块
+export const routes = [
+ {
+ path: '/parent',
+ children: [
+ {
+ path: '/child/:id1?',
+ component: async () => import('@/components/Child.vue'),
+ children: [
+ {
+ path: '/grandchild/:id2?',
+ component: async () => import('@/components/Grandchild.vue'),
+ }
+ ]
+ }
+ ],
+ },
+]
+```
+
+
+
+### 综合题目
+
+#### 题目6:嵌套路由的综合应用
+
+**任务描述**:创建一个包含多个层级嵌套路由的项目,模拟一个简单的电商系统。父路由为 `/home`,子路由包括 `/products`(产品列表)、`/cart`(购物车)、`/user`(用户中心)。每个子路由下还可以有更细的路由,例如 `/products/:id`(产品详情页)。
+
+**要求**:
+
+1. 配置多级嵌套路由。
+2. 在父路由组件中提供导航链接,跳转到不同的子路由。
+3. 在子路由组件中实现具体的功能,例如产品列表页显示产品列表,产品详情页显示产品详情。
+4. 使用动态路由匹配和路由参数传递数据。
+
+
+**提示**:
+
+- 使用嵌套路由配置。
+- 使用动态路由匹配。
+
+```vue
+
+ 电商系统
+
+
+ 产品列表
+ 购物车
+ 用户中心
+
+
+
+
+
+
+
+
+```
+
+```vue
+
+ {{ $route.params.id ? `商品ID【${$route.params.id}】的产品详情` : "商品列表" }}
+
+```
+
+```vue
+
+ 购物车
+
+```
+
+```vue
+
+ 用户中心
+
+```
+
+```js
+// 导出Vue路由模块
+export const routes = [
+ {
+ path: '/home',
+ children: [
+ {
+ path: '/products/:id?',
+ component: async () => import('@/components/Products.vue'),
+ },
+ {
+ path: '/cart',
+ component: async () => import('@/components/Cart.vue'),
+ },
+ {
+ path: '/user',
+ component: async () => import('@/components/User.vue'),
+ },
+ ],
+ },
+]
+```
+
--
Gitee
From c2f6e63fa9401893389a1e46da2a0695082a322d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E6=98=BE=E4=B9=89?= <3515252188@qq.com>
Date: Thu, 29 May 2025 19:06:06 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=83=E4=B9=A0=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...45\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md" | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename "\347\216\213\346\230\276\344\271\211/\345\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md" => "\347\216\213\346\230\276\344\271\211/20250529 \345\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md" (100%)
diff --git "a/\347\216\213\346\230\276\344\271\211/\345\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md" "b/\347\216\213\346\230\276\344\271\211/20250529 \345\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md"
similarity index 100%
rename from "\347\216\213\346\230\276\344\271\211/\345\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md"
rename to "\347\216\213\346\230\276\344\271\211/20250529 \345\237\272\347\241\200\347\273\203\344\271\240\351\242\230.md"
--
Gitee