左侧侧边栏导航

博客围绕左侧侧边栏导航展开,但具体内容缺失。侧边栏导航是常见的网页布局元素,在前端开发中应用广泛,能为用户提供便捷的导航功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <el-col :span="24" class="main">
    <!--左侧导航-->
    <aside :class="{showSidebar:!collapsed}">
      <!--展开折叠开关-->
      <div class="menu-toggle" @click.prevent="collapse">
        <i class="iconfont icon-shouqi" v-show="!collapsed" title="收起"  style="font-size: 18px;"></i>
        <i class="iconfont icon-zhankai" v-show="collapsed" title="展开"  style="font-size: 20px;"></i>
      </div>
      <!--导航菜单-->
      <el-menu :default-active="cur_path" router :collapse="collapsed" ref="leftNavigation"  :unique-opened=true>
            <!-- <el-submenu :index="item.path"  v-for="(item,index) in navarr" :key="index">  
          		<template slot="title">
						<i :class="item.iconCls" style="color:#fff;font-size: 20px;margin-right: 5px;"></i>
						<span>{{item.name}}</span>
					</template>
						<el-menu-item-group  v-for="(item2,index) in item.children"  :key="index">
							<el-menu-item :index="item2.path" >
								<i :class="item2.iconCls" style="color:#fff;font-size: 23px;margin-right: 8px;"></i>
								{{item2.name}}
							</el-menu-item>

							
						</el-menu-item-group>
				
             </el-submenu> -->


                <el-submenu :index="item.root_id"  v-for="(item,index) in navarr" :key="index">  
          		<template slot="title">
						<i :class="item.root_icon" style="color:#fff;font-size: 20px;margin-right: 5px;"></i>
						<span>{{item.root_name}}</span>
					</template>
						<el-menu-item-group  v-for="(item2,index) in item.subItem"  :key="index">
							<el-menu-item :index="'/'+item2.root_url" >
								<i :class="item2.root_icon" style="color:#fff;font-size: 23px;margin-right: 8px;"></i>
								{{item2.root_name}}
							</el-menu-item>

							
						</el-menu-item-group>
				
             </el-submenu  >
                







     
      </el-menu>
    </aside>
    <!--右侧内容区-->
    <section class="content-container">
      <div class="grid-content bg-purple-light">
        <el-col :span="24" class="content-wrapper">
          <transition name="fade" mode="out-in">
            <router-view></router-view>
          </transition>
        </el-col>
      </div>
    </section>
  </el-col>
</template>
<script>
  export default {
    name: 'leftNav',
    data () {
      return {
        collapsed: false,
        navarr:[],cur_path:'/Basic_statistics',
      }
    },
    methods: {
      //折叠导航栏
      collapse: function () {
        this.collapsed = !this.collapsed;
      },
      // 左侧导航栏根据当前路径默认打开子菜单(如果当前路由是三级,则父级子菜单默认打开)
      defaultLeftNavOpened () {
        let cur_path = this.$route.path; //获取当前路由
        let routers = this.$router.options.routes; // 获取路由对象
        
        let subMenuIndex = 0, needOpenSubmenu = false;
        for (let i = 0; i < routers.length; i++) {
          let children = routers[i].children;
          if(children){
            for (let j = 0; j < children.length; j++) {
              if (children[j].path === '/disiji') {
                break;
              }
              // 如果该菜单下有子菜单(个数>1且设置的leaf为false才有下拉子菜单)
              if(children[j].children && !children[j].leaf) {
                let grandChildren = children[j].children;
                for(let z=0; z<grandChildren.length; z++) {
                  if(grandChildren[z].path === cur_path) {
                    subMenuIndex = j;
                    needOpenSubmenu = true;
                    break;
                  }
                }
              }
            }
          }
        }
        if(this.$refs['leftNavigation'] && needOpenSubmenu) {
          this.$refs['leftNavigation'].open(subMenuIndex); // 打开子菜单
        }
      },
      // 判断是不是进入离线页面
      isnavarr () {
          let  that=this
        let cur_path = this.$route.path; //获取当前路由
        let routers = this.$router.options.routes; // 获取路由对象
        
        let subMenuIndex = 0, needOpenSubmenu = false;
        for (let i = 0; i < routers.length; i++) {
          if (routers[i].path === '/disiji') {
                 that.navarr=routers[i].children
              }
        }
      
      },
    }, 
    created(){
       
      
    },
    mounted() {
      this.navarr=[]
      let path_arr=[]
      let path_arr1=[]  
      var arr=this.$router.options.routes[6].children
        
         this.cur_path = this.$route.path; //获取当前路由
      this.collapsed=false
         var data = JSON.parse(localStorage.getItem("Menus"));  
         
         

        //  for (let i = 0; i < Menus[4].subItem.length; i++) {
        //     if (Menus[4].subItem[i].subItem.length>0) {
        //         for (let j = 0; j < Menus[4].subItem[i].subItem.length; j++) {
        //             path_arr.push('/'+Menus[4].subItem[i].subItem[j].root_url)
        //         }
        //     }
             
        //  }
         
        //   for (let i = 0; i < arr.length; i++) {
        //       for (let j = 0; j < arr[i].children.length; j++) {
        //            path_arr1.push(arr[i].children[j].path)
        //            if ( path_arr.indexOf(arr[i].children[j].path)<0) {
                       
        //           arr[i].children.splice(j,1)
        //            }
                  
        //       }
              
        //   }

          var Menus;
         var data = JSON.parse(localStorage.getItem("Menus"));  
            
        for (const k in data) {
           if (data[k].root_id=='05') {
               
             Menus  =data[k].subItem
             this.navarr=Menus   
           }
        }

                
    }
  }
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值