前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Element NavMenu 无限级菜单

Element NavMenu 无限级菜单

作者头像
tianyawhl
发布2020-02-17 08:02:09
1.5K0
发布2020-02-17 08:02:09
举报
文章被收录于专栏:前端之攻略

数据结构 

menudata.json

代码语言:javascript
复制
{"data":[
    {
       "id": 1,
        "path": "/home",
        "menuName": "商业数据统计",
        "component": "Home",
        "childMenu":[{
          "id": 2,
          "path": "/commercial/dataAccount/Day",
          "menuName": "日统计1",
          "component": "DataAccountDay"
        },
        {
          "id": 3,
          "path": "/commercial/dataAccount/Month",
          "menuName": "月统计1",
          "component": "DataAccountMonth"
        }]
      },
      {
        "id": 4,
        "path": "/home",
        "menuName": "商业报表中心",
        "component": "Home",
        "childMenu":[{
          "id": 5,
          "path": "/commercial/baobiao/Day",
          "menuName": "日报表1",
          "component": "BaobiaoDay"
        },
        {
          "id": 6,
          "path": "/commercial/baobiao/Month",
          "menuName": "月报表1",
          "component": "BaobiaoMonth"
        }]
      } 
    ]}

Home.vue

代码语言:javascript
复制
<template>
  <div>
    <el-container :style="{height: containerHeight, border: '1px solid #eee'}" id="con">
      <el-header style="background:#3c8dbc;">
        header
      </el-header>

      <el-container>
        <el-aside width="230px">
          <el-menu
            router
            :default-active="routePath"           
            unique-opened
            background-color="#1f3146"
            text-color="#32acca"
            active-text-color="#ffd04b"
          >
            <NavMenu :navMenus="menuData"></NavMenu>
          </el-menu>
        </el-aside>
        <el-container>
          <el-main>
            <router-view></router-view>
          </el-main>
          <el-footer>
            footer
          </el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import NavMenu from "@/components/NavMenu.vue";
export default {
  data() {
    return {
      containerHeight: "",     
      menuData: [],
      routePath:"",
      currentModuleChinese:"",
      user: window.sessionStorage.getItem("user")
    };
  },
  created() {
    this.$axios.get("/mock/menudata + ".json").then(res => {-      
      this.menuData = res.data.data;     
    }); 
  },
  components: { NavMenu },
  // watch:{
  //  $route(){
  //    console.log(this.$route.path)
  //    this.routePath = this.$route.path
  //  }
  // },
  mounted() { 
    console.log("mounted")   
    this.containerHeight = window.innerHeight + "px";
    console.log($)
    $(window).resize(function() {
      console.log("hi")
      $("#con").height($(window).height()-2);
    });
  }
};
</script>

<style>
.el-header {
  background-color: #377fa9;
  color: #fff;
  height: 50px !important;
  line-height: 50px !important;
}

.el-header .left img {
  width: 120px;
  vertical-align: middle;
}
.el-header .left span {
  font-size: 20px;
  color: #edf8ff;
  margin-left: 15px;
}
.el-header .right {
  float: right;
}
.el-header .right a {
  color: #fff;
}
.el-aside {
  /* color: #32acca !important; */
  background: #1f3146 !important;
}
.el-menu {
  border-right: none !important;
  /* background: #1f3146 !important; */
}
.el-footer {
  background: gray;
  height: 40px !important;
  line-height: 40px !important;
}
.el-footer {
  border-top: 1px solid #ccc;
  background: #f8fafd;
  padding: 10px;
  margin-left: 0;
}
.el-footer img {
  vertical-align: middle;
  width: 65px;
  margin-right: 10px;
}
</style>

NavMenu.vue

代码语言:javascript
复制
<template>
  <div>
    <template v-for="(item,index) in navMenus">
      <!-- 含有子菜单 -->
      <el-submenu v-if="item.childMenu && item.childMenu.length>0" :key="index" :index="index+''">
        <template slot="title">
          <i class="el-icon-setting"></i>
          <!-- <img :src="item.info.picUrl" alt=""> -->
          <span>{{item.menuName}}</span>
        </template>
        <NavMenu :navMenus="item.childMenu"></NavMenu>
      </el-submenu>
      <!-- 最后一级 -->
      <el-menu-item v-else :key="index" :index="item.path">{{item.menuName}}</el-menu-item>
    </template>
  </div>
</template>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 数据结构 
相关产品与服务
腾讯云 BI
腾讯云 BI(Business Intelligence,BI)提供从数据源接入、数据建模到数据可视化分析全流程的BI能力,帮助经营者快速获取决策数据依据。系统采用敏捷自助式设计,使用者仅需通过简单拖拽即可完成原本复杂的报表开发过程,并支持报表的分享、推送等企业协作场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档