submenu.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <template v-for="(item, index) in dataList" :key="index">
  3. <el-sub-menu :index="item.code" :show-timeout="100" :hide-timeout="100" v-if="item.children?.length">
  4. <template #title>
  5. <!--如果没有图标,用标题第一个字代替-->
  6. <template v-if="item.icon">
  7. <app-icon class="menu-icon" :icon="item.icon" />
  8. <span>{{ t(item.title) }}</span>
  9. </template>
  10. <template v-else>
  11. <i class="menu-icon menu-icon--text">{{ item.title.slice(0, 1) }}</i>
  12. <span>{{ item.title.slice(1) }}</span>
  13. </template>
  14. </template>
  15. <!--如果存在子级,递归组件自身-->
  16. <app-submenu :data-list="item.children" />
  17. </el-sub-menu>
  18. <el-menu-item :index="item.code" v-else>
  19. <app-icon class="menu-icon" :icon="item.icon" v-if="item.icon" />
  20. <span>{{ t(item.title) }}</span>
  21. </el-menu-item>
  22. </template>
  23. </template>
  24. <script lang="ts">
  25. import { defineComponent, PropType } from 'vue'
  26. import { i18n } from '@/stores';
  27. import AppIcon from '@pc/components/base/icon/index.vue'
  28. export default defineComponent({
  29. name: 'AppSubmenu',
  30. components: {
  31. AppIcon
  32. },
  33. props: {
  34. dataList: {
  35. type: Array as PropType<Model.UserRoutes[]>,
  36. required: true,
  37. },
  38. },
  39. setup() {
  40. const { global: { t } } = i18n
  41. return { t }
  42. }
  43. })
  44. </script>