<template>
    <el-menu :router="true"
            :default-active="defaultMItem"
            class="el-menu-vertical-demo">
        <template v-for="(item,index) in data">
            <el-menu-item :index="'/'+role+'/'+item.code" v-if="item.subMenuList.length==0">
                <i v-bind:class="icons[item.code]"></i>
                <span slot="title">{{item.name}}</span>
            </el-menu-item>
            <el-submenu v-if="item.subMenuList.length>0" :index="index+1+''">
                <template slot="title">
                    <i class="el-icon-location"></i>
                    <span>{{item.name}}</span>
                </template>
                <el-menu-item v-for="(sub,i) in item.subMenuList" :index="'/'+role+'/'+sub.code">{{sub.name}}</el-menu-item>
            </el-submenu>
        </template>
    </el-menu>
</template>

<script>
  import config from '@api/config.js';

  export default {
    name: 'lt-menu',
    props: ['data', 'role'],
    data: function () {
      return {
        icons: config.menuIconList
      }
    },
    computed:{
        defaultMItem:function () {
            let route = this.$route.path;
            return route;
        }
    },
    methods: {
    }
  }
</script>