vue二級(jí)路由設(shè)置方法
項(xiàng)目當(dāng)中使用vue的時(shí)候一定會(huì)用到路由,并且二級(jí)路由甚至三集路由的需求都是剛需,當(dāng)然,多級(jí)路由的配置方法和二級(jí)的是一樣的,簡(jiǎn)單講講二級(jí)路由的配置吧。
首先把一級(jí)路由的結(jié)構(gòu)準(zhǔn)備好:
<router-link to="/discover">
<div @click="clickFind('發(fā)現(xiàn)')">
<span class="icon-find"></span>
<p>發(fā)現(xiàn)</p>
</div>
</router-link>
<router-link to="/todayStudy">
<div @click="clickStudy('今日學(xué)習(xí)')">
<span class="icon-todayStudy"></span>
<p>今日學(xué)習(xí)</p>
</div>
</router-link>
<router-link to="/listenAnyWhere">
<div @click="clickListen('隨時(shí)聽(tīng)')">
<span class="icon-listenAny"></span>
<p>隨時(shí)聽(tīng)</p>
</div>
</router-link>
<router-link to="/bought">
<div @click="clickBought('已購(gòu)')">
<span class="icon-areadyBy"></span>
<p>已購(gòu)</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
}
];
先看效果
點(diǎn)擊每天聽(tīng)本書(shū)后進(jìn)入下一級(jí)
在main.js里設(shè)置二級(jí)路由
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>
},
在相應(yīng)的路徑下建立各個(gè)路由所需模塊即可
以上這篇vue二級(jí)路由設(shè)置方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue中動(dòng)態(tài)class的多種寫(xiě)法
這篇文章主要介紹了Vue之動(dòng)態(tài)class的幾種寫(xiě)法,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-12-12
vue實(shí)現(xiàn)一個(gè)單文件組件的完整過(guò)程記錄
整個(gè)項(xiàng)目結(jié)構(gòu)清晰,尤其單文件組件的表現(xiàn)力尤為突出,使得每個(gè)組件的邏輯都沒(méi)有過(guò)于復(fù)雜,所以這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)一個(gè)單文件組件的相關(guān)資料,需要的朋友可以參考下2021-06-06
vue.js實(shí)現(xiàn)簡(jiǎn)單購(gòu)物車功能
這篇文章主要為大家詳細(xì)介紹了vue.js實(shí)現(xiàn)簡(jiǎn)單購(gòu)物車功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05
vue+flask實(shí)現(xiàn)視頻合成功能(拖拽上傳)
這篇文章主要介紹了vue+flask實(shí)現(xiàn)視頻合成功能(拖拽上傳),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
vue+axios全局添加請(qǐng)求頭和參數(shù)操作
這篇文章主要介紹了vue+axios全局添加請(qǐng)求頭和參數(shù)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
VUE 解決mode為history頁(yè)面為空白的問(wèn)題
今天小編就為大家分享一篇VUE 解決mode為history頁(yè)面為空白的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11
Vue2中compiler和runtime模式報(bào)錯(cuò)template compiler is 
本文主要介紹了Vue2中compiler和runtime模式報(bào)錯(cuò)template compiler is not available,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07

