menu.vue 1.93 KB
<template>
  <div class="box">
    <el-menu
      :default-active="activemenu"
      class="el-menu-vertical-demo"
      :collapse="isCollapse"
      @select="handleSelect"
    >
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-location"></i>
          <span slot="title">首页</span>
        </template>
        <el-menu-item index="/trficcshow">
          <i class="el-icon-location"></i>交通展示
        </el-menu-item>
        <el-menu-item index="/behaviorshow">
          <i class="el-icon-location"></i>综治展示
        </el-menu-item>
      </el-submenu>
      <el-submenu  v-for="(fristmenu,index) in permission_routers" :index="fristmenu.path" :key="index">
        <template slot="title">
          <i :class="fristmenu.meta.icon"></i>
          <span slot="title">{{fristmenu.name}}</span>
        </template>
        <el-menu-item  v-for="(twomenu,index) in fristmenu.children" :key="index" :index="twomenu.path">
          <i :class="twomenu.meta.icon"></i>{{twomenu.name}}
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";

export default {
  data() {
    return {
      full: false,
      isCollapse: false,
      activemenu: "/search/vehicleSearch"
    };
  },
  methods: {
    handleSelect(key, keyPath) {
      this.$router.push(key);
      localStorage.setItem("curmenu", key);
      console.log(key, keyPath);
    }
  },
  computed: {
    ...mapGetters(["permission_routers"])
  },
  created() {
    let activemenu = localStorage.getItem("curmenu");
    let menus = JSON.parse(localStorage.getItem('menu'))
    if(menus) {
      	this.$store.dispatch('GetMenuRole',menus).then(res => {
         if (activemenu) {
            this.activemenu = activemenu;
          } else {
            this.$router.push("/");
          }
        })
    }
    
  }
};
</script>

<style lang="stylus" scoped>
.box{
  height 100%;
}
</style>