溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue.js實現(xiàn)左邊導(dǎo)航切換右邊內(nèi)容的方法

發(fā)布時間:2021-04-19 11:33:16 來源:億速云 閱讀:632 作者:小新 欄目:web開發(fā)

小編給大家分享一下vue.js實現(xiàn)左邊導(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, // 是否存在二級菜單,true為存在
  // path: 'background',
  navSecond: [
  {name: '創(chuàng)建背景', path: 'background'},
  {name: '創(chuàng)建單位', path: 'unit'},
  {name: '創(chuàng)建目的'},
  {name: '管理單位'},
  {name: '運行主體'}
  ]
  },
  {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)屬于子菜單時,父菜單高亮
  }
  }
  })
 } 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)屬于子菜單時,父菜單高亮
  }
  }
  })
  } 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>

效果圖:

vue.js實現(xiàn)左邊導(dǎo)航切換右邊內(nèi)容的方法

vue.js實現(xiàn)左邊導(dǎo)航切換右邊內(nèi)容的方法

vue.js實現(xiàn)左邊導(dǎo)航切換右邊內(nèi)容的方法

以上是“vue.js實現(xiàn)左邊導(dǎo)航切換右邊內(nèi)容的方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI