下面我就為大家分享一篇vue二級路由設定方法,具有很好的參考價值,希望對大家有幫助。
專案當中使用vue的時候一定會用到路由,並且二級路由甚至三集路由的需求都是剛需,當然,多級路由的配置方法和二級的是一樣的,簡單講講二級路由的配置吧。
先把一級路由的結構準備好:
<router-link to="/discover"> <p @click="clickFind('发现')"> <span class="icon-find"></span> <p>发现</p> </p> </router-link> <router-link to="/todayStudy"> <p @click="clickStudy('今日学习')"> <span class="icon-todayStudy"></span> <p>今日学习</p> </p> </router-link> <router-link to="/listenAnyWhere"> <p @click="clickListen('随时听')"> <span class="icon-listenAny"></span> <p>随时听</p> </p> </router-link> <router-link to="/bought"> <p @click="clickBought('已购')"> <span class="icon-areadyBy"></span> <p>已购</p> </p> </router-link> <router-link to="/mine"> <p @click="clickMe"> <span class="icon-me"></span> <p>我</p> </p> </router-link> </p> <router-view></router-view>
在main.js裡引入模組,並設定路由:
import discover from './components/discover/discover.vue'; import todayStudy from './components/todayStudy/study.vue'; import listen from './components/listenAnyWhere/listen.vue'; import bought from './components/bought/bought.vue'; import mine from './components/mine/mine.vue';
const routes = [ { path: '/', redirect: '/discover' }, { path: '/discover', component: discover }, { path: '/todayStudy', component: todayStudy }, { path: '/listenAnyWhere', component: listen }, { path: '/bought', component: bought }, { path: '/mine', component: mine } ];
先看效果
##
點擊每天聽本書後進入下一級
在main.js裡設定二級路由
import thisMouth from './components/discover/detailEveryDay/thisMouth/thisMouth.vue'; import four from './components/discover/detailEveryDay/fourth/fourth.vue'; import three from './components/discover/detailEveryDay/three/third.vue'; import two from './components/discover/detailEveryDay/two/second.vue'; import one from './components/discover/detailEveryDay/one/first.vue'; import twel from './components/discover/detailEveryDay/twe/twel.vue'; import elev from './components/discover/detailEveryDay/elven/elev.vue';
const routes = [ { path: '/', redirect: '/discover' }, { path: '/discover', component: discover, <span style="color:#ff0000;">children: [ { path: '/', component: thisMouth }, { path: '/thisMouth', component: thisMouth }, { path: '/forthMouth', component: four }, { path: '/thirdMouth', component: three }, { path: '/secondMouth', component: two }, { path: '/firstMouth', component: one }, { path: '/elMouth', component: twel }, { path: '/twMouth', component: elev } ]</span> },
在對應的路徑下建立各個路由所需模組即可
##上面是我整理給大家的,希望未來會對大家有幫助。
相關文章:
在mint-ui中使用時間外掛程式及取得選擇值VUE2實現二級省市聯動選擇在vue中全選實現資料的綁定及取得以上是使用vue實作二級路由設定方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!