vue多層嵌套路由實(shí)例分析
本文實(shí)例講述了vue多層嵌套路由。分享給大家供大家參考,具體如下:
多層嵌套:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="bower_components/vue/dist/vue.js"></script>
<script src="bower_components/vue-router/dist/vue-router.js"></script>
<style>
.v-link-active{
font-size: 20px;
color: #f60;
}
</style>
</head>
<body>
<div id="box">
<ul>
<li>
<a v-link="{path:'/home'}">主頁(yè)</a>
</li>
<li>
<a v-link="{path:'/news'}">新聞</a>
</li>
</ul>
<div>
<router-view></router-view>
</div>
</div>
<template id="home">
<h3>我是主頁(yè)</h3>
<div>
<a v-link="{path:'/home/login'}">登錄</a>
<a v-link="{path:'/home/reg'}">注冊(cè)</a>
</div>
<div>
<router-view></router-view>
</div>
</template>
<template id="news">
<h3>我是新聞</h3>
</template>
<script>
//1. 準(zhǔn)備一個(gè)根組件
var App=Vue.extend();
//2. Home News組件都準(zhǔn)備
var Home=Vue.extend({
template:'#home'
});
var News=Vue.extend({
template:'#news'
});
//3. 準(zhǔn)備路由
var router=new VueRouter();
//4. 關(guān)聯(lián)
router.map({
'home':{
component:Home,
subRoutes:{
'login':{
component:{
template:'<strong>我是登錄信息</strong>'
}
},
'reg':{
component:{
template:'<strong>我是注冊(cè)信息</strong>'
}
}
}
},
'news':{
component:News
}
});
//5. 啟動(dòng)路由
router.start(App,'#box');
//6. 跳轉(zhuǎn)
router.redirect({
'/':'home'
});
</script>
</body>
</html>
效果圖:

路由其他信息:
/detail/:id/age/:age
{{$route.params | json}} -> 當(dāng)前參數(shù)
{{$route.path}} -> 當(dāng)前路徑
{{$route.query | json}} -> 數(shù)據(jù)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="bower_components/vue/dist/vue.js"></script>
<script src="bower_components/vue-router/dist/vue-router.js"></script>
<style>
.v-link-active{
font-size: 20px;
color: #f60;
}
</style>
</head>
<body>
<div id="box">
<ul>
<li>
<a v-link="{path:'/home'}">主頁(yè)</a>
</li>
<li>
<a v-link="{path:'/news'}">新聞</a>
</li>
</ul>
<div>
<router-view></router-view>
</div>
</div>
<template id="home">
<h3>我是主頁(yè)</h3>
<div>
<a v-link="{path:'/home/login/zns'}">登錄</a>
<a v-link="{path:'/home/reg/strive'}">注冊(cè)</a>
</div>
<div>
<router-view></router-view>
</div>
</template>
<template id="news">
<h3>我是新聞</h3>
<div>
<a v-link="{path:'/news/detail/001'}">新聞001</a>
<a v-link="{path:'/news/detail/002'}">新聞002</a>
</div>
<router-view></router-view>
</template>
<template id="detail">
{{$route.params | json}}
<br>
{{$route.path}}
<br>
{{$route.query | json}}
</template>
<script>
//1. 準(zhǔn)備一個(gè)根組件
var App=Vue.extend();
//2. Home News組件都準(zhǔn)備
var Home=Vue.extend({
template:'#home'
});
var News=Vue.extend({
template:'#news'
});
var Detail=Vue.extend({
template:'#detail'
});
//3. 準(zhǔn)備路由
var router=new VueRouter();
//4. 關(guān)聯(lián)
router.map({
'home':{
component:Home,
subRoutes:{
'login/:name':{
component:{
template:'<strong>我是登錄信息 {{$route.params | json}}</strong>'
}
},
'reg':{
component:{
template:'<strong>我是注冊(cè)信息</strong>'
}
}
}
},
'news':{
component:News,
subRoutes:{
'/detail/:id':{
component:Detail
}
}
}
});
//5. 啟動(dòng)路由
router.start(App,'#box');
//6. 跳轉(zhuǎn)
router.redirect({
'/':'home'
});
</script>
</body>
</html>
效果圖:

希望本文所述對(duì)大家vue.js程序設(shè)計(jì)有所幫助。
- vue+element使用動(dòng)態(tài)加載路由方式實(shí)現(xiàn)三級(jí)菜單頁(yè)面顯示的操作
- vue自定義標(biāo)簽和單頁(yè)面多路由的實(shí)現(xiàn)代碼
- vue自動(dòng)路由-單頁(yè)面項(xiàng)目(非build時(shí)構(gòu)建)
- Vue.js 單頁(yè)面多路由區(qū)域操作的實(shí)例詳解
- vue-router單頁(yè)面路由
- 解決vue-router 嵌套路由沒(méi)反應(yīng)的問(wèn)題
- vue 路由緩存 路由嵌套 路由守衛(wèi) 監(jiān)聽(tīng)物理返回操作
- vue2路由方式--嵌套路由實(shí)現(xiàn)方法分析
- Vue2.0使用嵌套路由實(shí)現(xiàn)頁(yè)面內(nèi)容切換/公用一級(jí)菜單控制頁(yè)面內(nèi)容切換(推薦)
- 詳解vue路由篇(動(dòng)態(tài)路由、路由嵌套)
- vue 在單頁(yè)面應(yīng)用里使用二級(jí)套嵌路由
相關(guān)文章
Vue調(diào)用PC攝像頭實(shí)現(xiàn)拍照功能
這篇文章主要為大家詳細(xì)介紹了Vue調(diào)用PC攝像頭實(shí)現(xiàn)拍照功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09
vue實(shí)現(xiàn)點(diǎn)擊按鈕下載文件功能
這篇文章主要介紹了vue中點(diǎn)擊按鈕下載文件,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-10-10
vue實(shí)現(xiàn)垂直無(wú)限滑動(dòng)日歷組件
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)垂直無(wú)限滑動(dòng)日歷組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
vue如何處理base64格式文件pdf及圖片預(yù)覽功能
這篇文章主要給大家介紹了關(guān)于vue如何處理base64格式文件pdf及圖片預(yù)覽功能的相關(guān)資料,圖片的base64編碼就是可以將一副圖片數(shù)據(jù)編碼成一串字符串,使用該字符串代替圖像地址,需要的朋友可以參考下2024-05-05
詳解Vue Elememt-UI構(gòu)建管理后臺(tái)
本篇文章給大家詳細(xì)分享了Vue Elememt-UI構(gòu)建管理后臺(tái)的過(guò)程以及相關(guān)代碼實(shí)例,一起參考學(xué)習(xí)下。2018-02-02
vue路由組件路徑如何用變量形式動(dòng)態(tài)引入
這篇文章主要介紹了vue路由組件路徑如何用變量形式動(dòng)態(tài)引入問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06

