<template>
  <el-sub-menu v-if="props.item.children.length > 0" :index="props.index">
    <template #title>
      <span>{{ props.item.name }}</span>
    </template>
    <template v-for="(ite, indey) in props.item.children" :key="ite.path">
      <sidebarItem :item="ite" :index="`${index}-${indey}`" />
    </template>
  </el-sub-menu>
  <el-menu-item v-else :index="props.index" @click="menuClick(props.item.path)">{{ props.item.name }}</el-menu-item>
</template>

<script lang="ts">
export default {
  name: "sidebarItem"
};
</script>

<script setup lang="ts">
import { useRouter } from "vue-router";

const router = useRouter();
const props = defineProps({
  item: {
    type: Object,
    default: () => ({})
  },
  index: {
    type: String,
    default: undefined
  }
});

const menuClick = (item: any) => {
  router.push(item);
};
</script>

<style lang="scss" scoped></style>
