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'}">主頁</a> </li> <li> <a v-link="{path:'/news'}">新聞</a> </li> </ul> <div> <router-view></router-view> </div> </div> <template id="home"> <h3>我是主頁</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'}">主頁</a> </li> <li> <a v-link="{path:'/news'}">新聞</a> </li> </ul> <div> <router-view></router-view> </div> </div> <template id="home"> <h3>我是主頁</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í)菜單頁面顯示的操作
- vue自定義標(biāo)簽和單頁面多路由的實(shí)現(xiàn)代碼
- vue自動(dòng)路由-單頁面項(xiàng)目(非build時(shí)構(gòu)建)
- Vue.js 單頁面多路由區(qū)域操作的實(shí)例詳解
- vue-router單頁面路由
- 解決vue-router 嵌套路由沒反應(yīng)的問題
- vue 路由緩存 路由嵌套 路由守衛(wèi) 監(jiān)聽物理返回操作
- vue2路由方式--嵌套路由實(shí)現(xiàn)方法分析
- Vue2.0使用嵌套路由實(shí)現(xiàn)頁面內(nèi)容切換/公用一級(jí)菜單控制頁面內(nèi)容切換(推薦)
- 詳解vue路由篇(動(dòng)態(tài)路由、路由嵌套)
- vue 在單頁面應(yīng)用里使用二級(jí)套嵌路由
相關(guān)文章
vue項(xiàng)目中如何配置eslint和prettier
這篇文章主要介紹了vue項(xiàng)目中如何配置eslint和prettier問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03詳解關(guān)于vue2.0工程發(fā)布上線操作步驟
這篇文章主要介紹了詳解關(guān)于vue2.0工程發(fā)布上線操作步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09vue實(shí)現(xiàn)進(jìn)入某個(gè)頁面后替換地址欄路徑的操作方法
vue頁面在實(shí)際開發(fā)中,經(jīng)常會(huì)遇到改變url參數(shù),重新加載頁面數(shù)據(jù)的需求,但是只改變頁面url并不會(huì)觸發(fā)組件的生命周期,這就需要用其他方法來實(shí)現(xiàn)了,本文重點(diǎn)介紹vue實(shí)現(xiàn)進(jìn)入某個(gè)頁面后替換地址欄路徑的操作方法,感興趣的朋友跟隨小編一起看看吧2024-04-04巧妙運(yùn)用v-model實(shí)現(xiàn)父子組件傳值的方法示例
這篇文章主要介紹了巧妙運(yùn)用v-model實(shí)現(xiàn)父子組件傳值的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-04-04vue2 el-checkbox-group復(fù)選框無法選中問題及解決
這篇文章主要介紹了vue2 el-checkbox-group復(fù)選框無法選中問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-05-05