您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“vue下如何設置二級路由”,內容詳細,步驟清晰,細節處理妥當,希望這篇“vue下如何設置二級路由”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
首先把一級路由的結構準備好:
<router-link to="/discover"> <div @click="clickFind('發現')"> <span class="icon-find"></span> <p>發現</p> </div> </router-link> <router-link to="/todayStudy"> <div @click="clickStudy('今日學習')"> <span class="icon-todayStudy"></span> <p>今日學習</p> </div> </router-link> <router-link to="/listenAnyWhere"> <div @click="clickListen('隨時聽')"> <span class="icon-listenAny"></span> <p>隨時聽</p> </div> </router-link> <router-link to="/bought"> <div @click="clickBought('已購')"> <span class="icon-areadyBy"></span> <p>已購</p> </div> </router-link> <router-link to="/mine"> <div @click="clickMe"> <span class="icon-me"></span> <p>我</p> </div> </router-link> </div> <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 >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> },
在相應的路徑下建立各個路由所需模塊即可
讀到這里,這篇“vue下如何設置二級路由”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。