国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue2 中二級路由高亮問題及配置方法

2019-11-19 11:21:45
字體:
供稿:網(wǎng)友

實(shí)現(xiàn)效果圖

 

1、項(xiàng)目中的圖標(biāo)使用的是element-ui框架中的圖標(biāo),如果需要引入可以看我寫的上一篇文章。

2、首先配置路由

我初始化項(xiàng)目的時(shí)候初始化了路由,所以打開router/index.js文件進(jìn)行修改配置

router/index.js

import Vue from 'vue'import Router from 'vue-router'import Home from '@/components/Home'import Game from '@/components/Game'import Bbs from '@/components/Bbs'import Me from '@/components/Me'import Nba from '@/components/Nba'import Recommend from '@/components/Recommend'

Vue.use(Router)

export default new Router({ mode: 'history', linkActiveClass: 'active', routes: [ { path: '/', redirect: '/home' }, // 重定向到 home {  path: '/home',  name: 'Home',  component: Home,  // children path中"/home/"可以省略  children: [  {   path: '/',     // 子路由重定向   redirect: 'recommend'  },  {   path: 'recommend',   name: 'recommend',   component: Recommend  },  {   path: 'nba',   name: 'nba',   component: Nba  },  {   path: 'video',   name: 'video',   component: Nba  },  {   path: 'entertain',   name: 'entertain',   component: Nba  }  ] }, {  path: '/game',  name: 'Game',  component: Game }, {  path: '/bbs',  name: 'Bbs',  component: Bbs }, {  path: '/me',  name: 'Me',  component: Me } ]})

app.vue

底部導(dǎo)航封裝為TabBar組件,在app.vue中引入

<template> <div id="app"> <div :class="{router: true}">  <router-view/> </div> <!-- 底部導(dǎo)航組件 --> <div :class="{tabbar: true}">  <tab-bar></tab-bar> </div> </div></template><script>import TabBar from './components/Tabs'export default { name: 'App', components: { // 底部導(dǎo)航組件 TabBar }}</script><style scoped> #app { width: 100%; height: 100%; display: flex; flex-direction: column; } .router { flex: 1; padding: 10pt; } .tabbar { height: 30pt; padding: 10pt 0; border-top: 1pt solid #e6e6e6; background: #fbfbfb; }</style>

Tabs.vue

<template> <div id="tabs"> <div class="home">  <!-- 點(diǎn)擊其他tab頁,再次點(diǎn)擊home的時(shí)候,路由重定向到了recommend,注意寫法 to="/home/" -->  <router-link to="/home/" tag="div">   <div><i class="el-icon-s-home"></i></div>  <div>首頁</div>  </router-link> </div> <div class="game">  <router-link :to="{name: 'Game'}" tag="div">   <div><i class="el-icon-s-goods"></i></div>  <div>比賽</div>  </router-link> </div> <div class="bbs">  <router-link :to="{name: 'Bbs'}" tag="div">   <div><i class="el-icon-share"></i></div>  <div>社區(qū)</div>  </router-link> </div> <div class="me">  <router-link :to="{name: 'Me'}" tag="div">   <div><i class="el-icon-s-custom"></i></div>  <div>我</div>  </router-link> </div> </div></template><script>export default { name: 'TabBar'}</script><style scoped> #tabs {  width: 100%;  display: flex;  flex-direction: row;  justify-content: space-around;  align-items: center;  text-align: center;  color: #b5b5b5; } #tabs i {  font-size: 18pt; } .active {  color: #468dcc; }</style>

這樣就添加了底部導(dǎo)航,然后我們配置home界面,home界面中有二級導(dǎo)航,而且在首頁的二級導(dǎo)航選中的時(shí)候,需要高亮顯示”首頁“tab頁

Home.vue

<template> <div id="home"> <div :class="{topbar: true}">  <router-link :to="{name: 'recommend'}" tag="div">推薦</router-link>  <router-link :to="{name: 'nba'}" tag="div">籃球(NBA)</router-link>  <router-link :to="{name: 'video'}" tag="div">視頻</router-link>  <router-link :to="{name: 'entertain'}" tag="div">影視娛樂</router-link> </div> <div :class="{tabInfo: true}">  <router-view/> </div> </div></template><script>export default { name: 'Home', data () { return {  name: 'home' } }}</script><style scoped> #home { display: flex; flex-direction: column; text-align: left; height: 100%; } .topbar { height: 26pt; font-size: 12pt; color: #343434; background: #fbfbfb; border-bottom: 1pt solid #e6e6e6; margin-bottom: 10pt; display: flex; flex-direction: row; } .topbar div { margin: 0 5pt; } .topbar span { padding-bottom: 11pt; } .active { color: #468dcc; border-bottom: 1pt solid #468dcc; font-weight: bold; } .tabInfo { flex: 1; }</style>

總結(jié)

以上所述是小編給大家介紹的vue2 中二級路由 高亮問題及配置方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桂林市| 望江县| 邛崃市| 阿荣旗| 加查县| 涿州市| 荣昌县| 霍城县| 四平市| 崇文区| 仁寿县| 东阳市| 常山县| 团风县| 乌拉特前旗| 宁波市| 子洲县| 德清县| 四川省| 谢通门县| 武夷山市| 六盘水市| 沙湾县| 永川市| 广昌县| 河南省| 忻州市| 东丽区| 桂阳县| 缙云县| 屏东县| 封开县| 四子王旗| 扎兰屯市| 丘北县| 定边县| 柳河县| 墨脱县| 奈曼旗| 平南县| 胶南市|