Vue 嵌套路由
2022/2/14 23:43:33
本文主要是介绍Vue 嵌套路由,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Vue 嵌套路由
嵌套路由,也叫做多级路由
routes配置项里配好children属性
然后子路由组件中使用router-link和router-view标签即可
案例
routes.js
import VueRouter from 'vue-router' import Island from '../pages/Island' import Polaris from '../pages/Polaris' import IslandMessage from '../pages/IslandMessage' import IslandPhone from '../pages/IslandPhone' import PolarisMessage from '../pages/PolarisMessage' import PolarisPhone from '../pages/PolarisPhone' export default new VueRouter({ routes: [ { component: Island, path: "/Island", children: [ { path: 'IslandMessage', component: IslandMessage }, { path: 'IslandPhone', component: IslandPhone }, ] }, { component: Polaris, path: "/Polaris", children: [ { path: 'PolarisMessage', component: PolarisMessage }, { path: 'PolarisPhone', component: PolarisPhone } ] }, ] })
app.vue
<template> <div id="app"> <div class="nav"> <router-link class="nav" to="/Island" active-class="active-nav"> Island </router-link> <router-link class="nav" to="/Polaris" active-class="active-nav"> Polaris </router-link> </div> <div class="con"> <router-view /> </div> </div> </template>
Island.vue
<template> <div> <h1>message by Island</h1> <router-link to="/Island/IslandMessage">展示Island的message</router-link> <router-link to="/Island/IslandPhone">展示Island的message</router-link> <div> <router-view /> </div> </div> </template> <script> export default {}; </script> <style scoped> h1 { color: salmon; } </style>
这篇关于Vue 嵌套路由的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-04React 19 来了!新的编译器简直太棒了!
- 2025-01-032025年Node.js与PHP大比拼:挑选最适合的后端技术进行现代web开发
- 2025-01-03?? 用 Gemini API、Next.js 和 TailwindCSS 快速搭建 AI 推文生成项目 ??
- 2024-12-31Vue CLI多环境配置学习入门
- 2024-12-31Vue CLI学习入门:一步一步搭建你的第一个Vue项目
- 2024-12-31Vue3公共组件学习入门:从零开始搭建实用组件库
- 2024-12-31Vue3公共组件学习入门教程
- 2024-12-31Vue3学习入门:新手必读教程
- 2024-12-31Vue3学习入门:初学者必备指南
- 2024-12-30Vue CLI多环境配置教程:轻松入门指南