淺談vue 二級(jí)路由嵌套和二級(jí)路由高亮問(wèn)題
第一層路由我寫在app.vue里面。如圖所示:
footer.vue:
二級(jí)路由是這樣:
index.js里面的配置:
效果圖:
效果出來(lái)了,又出現(xiàn)新的問(wèn)題,就是點(diǎn)擊二級(jí)路由的時(shí)候,默認(rèn)的二級(jí)路由高亮不會(huì)去掉,如圖所示:
在網(wǎng)上看到別人用exact方法,即在默認(rèn)的二級(jí)路由里面加上exact,如圖所示:
補(bǔ)充知識(shí):vue - 子路由-路由嵌套
描述:子路由,也叫路由嵌套,采用在children后跟路由數(shù)組來(lái)實(shí)現(xiàn),數(shù)組里和其他配置路由基本相同,需要配置path和component,然后在相應(yīng)部分添加<router-view/>來(lái)展現(xiàn)子頁(yè)面信息,相當(dāng)于嵌入iframe。
Home.vue
<template> <div class='hello'> <h1>{{ msg }}</h1> <!-- 添加子路由導(dǎo)航 --> <p>導(dǎo)航 : <router-link to='/home'>首頁(yè)</router-link> | <router-link to='/home/one'>-子頁(yè)面1</router-link> | <router-link to='/home/two'>-子頁(yè)面2</router-link> </p> <!-- 子頁(yè)面展示部分 --> <router-view/> </div></template><script>export default { name: ’Home’, data () { return { msg: ’Home Page!’ } }}</script><style scoped></style>
One.vue /Two.vue
<template> <div class='hello'> <h1>{{ msg }}</h1> </div></template><script>export default { name: 'One', data() { return { msg: 'Welcome to One!' }; }};</script><!-- Add 'scoped' attribute to limit CSS to this component only --><style scoped>h1,h2 { font-weight: normal;}ul { list-style-type: none; padding: 0;}li { display: inline-block; margin: 0 10px;}a { color: #42b983;}</style>
index.js
import Vue from ’vue’import Router from ’vue-router’import Home from ’@/components/Home’import One from ’@/components/One’ import Two from ’@/components/Two’Vue.use(Router)export default new Router({ routes: [ { path: ’/’, // 默認(rèn)頁(yè)面重定向到主頁(yè) redirect: ’/home’ }, { path: ’/home’, // 主頁(yè)路由 name: ’Home’, component: Home, children:[ // 嵌套子路由 {path:’one’, // 子頁(yè)面1component:One }, {path:’two’, // 子頁(yè)面2component:Two }, ] } ]})
以上這篇淺談vue 二級(jí)路由嵌套和二級(jí)路由高亮問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. IntelliJ IDEA設(shè)置默認(rèn)瀏覽器的方法2. idea自定義快捷鍵的方法步驟3. IntelliJ IDEA設(shè)置背景圖片的方法步驟4. IntelliJ IDEA配置Tomcat服務(wù)器的方法5. python中復(fù)數(shù)的共軛復(fù)數(shù)知識(shí)點(diǎn)總結(jié)6. PHP腳本的10個(gè)技巧(8)7. IntelliJ IDEA導(dǎo)出項(xiàng)目的方法8. IntelliJ IDEA調(diào)整字體大小的方法9. jsp網(wǎng)頁(yè)實(shí)現(xiàn)貪吃蛇小游戲10. idea修改背景顏色樣式的方法
