<template>
  <div class='menu-wrapper'>
    <template v-for="item in routes">

      <!-- 不显示子菜单 -->
      <router-link v-if="!item.hidden && item.noDropdown && item.children.length > 0" :to="item.path+'/'+item.children[0].path">
        <el-menu-item :index="item.path+'/'+item.children[0].path" class='submenu-title-noDropdown'>
          <i v-if='item.icon' :icon-class="'el-icon-fa-' + item.icon"></i><span>{{item.children[0].name}}</span>
        </el-menu-item>
      </router-link>

      <!-- 显示子菜单 -->
      <el-submenu :index="item.name" v-if="!item.noDropdown && !item.hidden">
        <template slot="title">
          <i v-if='item.icon' :class="'el-icon-fa-' + item.icon"></i><span>{{item.name}}</span>
        </template>
        <template v-for="child in item.children" v-if='!child.hidden'>

          <sidebar-item class='nest-menu' v-if='child.children && child.children.length>0' :routes='[child]'> </sidebar-item>

          <router-link v-else :to="child.path">
            <el-menu-item :index="child.path">
              <span>{{child.name}}</span>
            </el-menu-item>
          </router-link>

        </template>

      </el-submenu>

    </template>
  </div>
</template>

<script>
export default {
  name: 'SidebarItem',
  props: {
    routes: {
      type: Array
    }
  }
}
</script>

