vue.js實(shí)現(xiàn)左邊導(dǎo)航切換右邊內(nèi)容
本文實(shí)例為大家分享了vue.js左邊導(dǎo)航切換右邊內(nèi)容的具體代碼,供大家參考,具體內(nèi)容如下
<template> <div class="layout-container"> <y-header> <div slot="nav"></div> </y-header> <div class="w"> <div class="content"> <div class="account-sidebar"> <div class="gray-box "> <div class="box-inner"> <ul class="account-nav"> <li v-for="(item,i) in nav" :key='i'> <a href="javascript:;" > <div class="account-nav-primary" @click="tabPrimary(item)" :class="{active:item.isActive}"> <span>{{item.name}}</span> <i class="el-icon-arrow-right"></i> </div> </a> <div v-if="item.secondNav==true"> <ul class="account-nav-second" v-show="show"> <li v-for="(itemT,j) in item.navSecond" :key='j' :class="{active:itemT.name===title}" @click="tabSecond(itemT)"> <span>{{itemT.name}}</span> </li> </ul> </div> </li> </ul> </div> </div> <div class="gray-box sidebar-bottom content-center"> <div class="img-code"> <img src="../../assets/static/img-code.png" width="100"/> </div> <span>掃一掃下載APP</span> </div> </div> <div class="account-content"> <router-view></router-view> </div> </div> </div> <y-footer></y-footer> </div> </template> <script> import YFooter from '/common/footer' import YHeader from '/common/header' export default { data () { return { show: true, title: '學(xué)院介紹', nav: [ {name: '學(xué)院介紹', isActive: false, secondNav: true, // 是否存在二級(jí)菜單,true為存在 // path: 'background', navSecond: [ {name: '創(chuàng)建背景', path: 'background'}, {name: '創(chuàng)建單位', path: 'unit'}, {name: '創(chuàng)建目的'}, {name: '管理單位'}, {name: '運(yùn)行主體'} ] }, {name: '關(guān)于我們', path: 'aboutMe', isActive: false, secondNav: false} ] } }, computed: { }, methods: { tabSecond (e) { this.$router.push({path: '/college/' + e.path}) }, tabPrimary (e) { let path = this.$route.path.split('/')[2] if (e.secondNav) { // this.show = !this.show if (path === 'aboutMe') { this.$router.push({path: '/college/' + e.navSecond[0].path}) } } else { this.$router.push({path: '/college/' + e.path}) } } }, created () { let path = this.$route.path.split('/')[2] this.nav.forEach(item => { item.isActive = false if (item.secondNav) { item.navSecond.forEach(itemT => { if (itemT.path === path) { this.title = itemT.name if (itemT.name === this.title) { item.isActive = true // 當(dāng)屬于子菜單時(shí),父菜單高亮 } } }) } else { if (item.path === path) { this.title = item.name item.isActive = true } } }) }, components: { YFooter, YHeader }, watch: { $route (to) { let path = to.path.split('/')[2] this.nav.forEach(item => { item.isActive = false if (item.secondNav) { item.navSecond.forEach(itemT => { if (itemT.path === path) { this.title = itemT.name if (itemT.name === this.title) { item.isActive = true // 當(dāng)屬于子菜單時(shí),父菜單高亮 } } }) } else { if (item.path === path) { this.title = item.name item.isActive = true } } }) } } } </script> <style lang="scss" rel="stylesheet/scss" scoped> @import "../../assets/style/mixin"; .main { background: #fff; color: #000; } a { color: #000; } .w { padding-top: 40px; } .img-code { margin: 0px auto 12px; } .content { display: flex; height: 100%; font-size: 16px; } .sidebar-bottom { margin-top: 20px; padding: 16px; } .content-center { text-align: center; } .account-sidebar { width: 210px; border-radius: 6px; .account-nav { padding: 15px 0; .active { color: #0156AC; } .active a{ color: #0156AC; } li:hover { a{ color: #0156AC; } } li { position: relative; line-height: 48px; .account-nav-primary { padding: 0px 20px; height: 48px; span { float: left; } i { float: right; line-height: 48px; font-size: 14px; } } .account-nav-second { li { list-style: disc; list-style-position: inside; height: 48px; padding: 0 26px; text-align: left; color: #5B6976; cursor: pointer; span { margin-left: -14px; color: #A9B2BC; } &:hover{ color: #0156AC; span { color: #0156AC; } } } .active { color: #0156AC; span { color: #0156AC; } } } a { display: block; } &.current { a { position: relative; z-index: 1; height: 50px; background-color: #98AFEE; line-height: 50px; color: #FFF; } } } } } .account-content { margin-left: 24px; flex: 1; } </style>
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue3+Elementplus實(shí)現(xiàn)面包屑功能
這篇文章主要為大家詳細(xì)介紹了Vue3如何結(jié)合Elementplus實(shí)現(xiàn)面包屑功能,文中的示例代碼簡(jiǎn)潔易懂,具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下2023-11-11webpack開發(fā)vue-cli的項(xiàng)目實(shí)踐
本文主要介紹了webpack開發(fā)vue-cli的項(xiàng)目實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法
這篇文章主要介紹了Vue項(xiàng)目中quill-editor帶樣式編輯器的使用方法,可以更改插入圖片和視頻,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08vue普通加密及國(guó)密SM2、SM3和sm4的使用例子
在我的項(xiàng)目中,甲方要求系統(tǒng)登錄時(shí)對(duì)密碼進(jìn)行加密后再傳給后端,指定使用國(guó)密SM3,下面這篇文章主要給大家介紹了關(guān)于vue普通加密及國(guó)密SM2、SM3和sm4使用的相關(guān)資料,需要的朋友可以參考下2022-12-12Vue動(dòng)態(tài)組件表格的實(shí)現(xiàn)代碼
這篇文章主要介紹了Vue動(dòng)態(tài)組件表格的實(shí)現(xiàn)代碼,包括框架結(jié)構(gòu)組件,文中還給大家封裝了幾個(gè)組件,有按鈕組件、圖片組件、滑動(dòng)開關(guān),結(jié)合示例代碼給大家詳細(xì)講解,需要的朋友可以參考下2022-10-10解決Vue3.0刷新頁(yè)面警告[Vue Router warn]:No match 
這篇文章主要介紹了解決Vue3.0刷新頁(yè)面警告[Vue Router warn]:No match found for location with path /xxx問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03vue elementui el-table 表格里邊展示四分位圖效果(功能實(shí)現(xiàn))
這篇文章主要介紹了vue elementui el-table 表格里邊展示四分位圖效果(功能實(shí)現(xiàn)),本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2024-04-04深入理解使用Vue實(shí)現(xiàn)Context-Menu的思考與總結(jié)
這篇文章主要介紹了使用Vue實(shí)現(xiàn)Context-Menu的思考與總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-03-03