menu.vue 2.56 KB
<template>
  <div class="menu-box">
    <el-menu :default-active="activeIndex" class="el-menu-hideafter" mode="horizontal"  @select="handleSelect">
         <el-menu-item  index="/show" >
          <template slot="title"><div class="menu-title"><i class="gy-icon-shouye menu-icon"></i>首页</div></template>
        </el-menu-item>
          <el-menu-item  v-for="(fristmenu,index) in permission_routers" :key="index" :index="fristmenu.path" v-if="fristmenu.children.length < 1">
            <i :class="[fristmenu.meta.icon,'menu-icon']"></i>{{fristmenu.name}}
          </el-menu-item>
          <el-submenu v-for="(fristmenu,index) in permission_routers" :key="index"  v-if="fristmenu.children.length > 0" :index="fristmenu.path" >
            <template slot="title"><i :class="[fristmenu.meta.icon,'menu-icon']"></i>{{fristmenu.name}}</template>
            <el-menu-item :class="{'dark-submenu':theme=='dark','white-submenu':them == 'white'}" v-for="(twomenu,index) in fristmenu.children" :key="index" :index="twomenu.path" v-if="twomenu.children.length < 1">{{twomenu.name}}</el-menu-item>
            <el-submenu  v-for="(twomenu,index) in fristmenu.children" :key="index" :index="twomenu.path" v-if="twomenu.children.length > 0">
                <template slot="title">{{twomenu.name}}</template>
                <el-menu-item v-for="(threemenu,index) in twomenu.children" :key="index" :index="threemenu.path">{{threemenu.name}}</el-menu-item>
            </el-submenu>
          </el-submenu>
    </el-menu>
  </div>
</template>
<script>
  import { mapGetters,mapState} from 'vuex'
  import Vue from 'vue'
  export default {
    data() {
      return {
        activeIndex: '/home',
      };
    },
    methods: {
      handleSelect(key, keyPath) {
        debugger
            sessionStorage.setItem('menu',key);
            this.$router.push(key);

      },
      selcurIndex(data){
        this.activeIndex = data
      },
    },
    computed: {
       ...mapState(['theme']),
      ...mapGetters([
        'permission_routers',
      ]),
    },
    created(){
      debugger
      console.log(this.theme)
      let menu =  sessionStorage.getItem('menu');
      if(menu) {
        this.activeIndex =  sessionStorage.getItem('menu');
        this.handleSelect(this.activeIndex);
      } else {
        this.activeIndex = '/show'
        this.handleSelect(this.activeIndex);
      }
    },
    watch:{
      theme(val){

      }
      // '$route':'changeRouter'
    }
  };

</script>
<style lang="stylus" scoped>
.menu-box {
  height 60px
  text-align center
  overflow hidden
  .menu-title{
  }
}
</style>