index.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <template>
  2. <div :class="['app-tab-component', direction]" v-if="dynamicComponents.length">
  3. <ul class="tab">
  4. <template v-for="(item, index) in dynamicComponents" :key="index">
  5. <li class="tab-item" @click="componentChange(index)">
  6. <slot :name="item.code" :item="item" :index="index">{{ item.title }}</slot>
  7. </li>
  8. </template>
  9. </ul>
  10. <div class="app-tab-component__container">
  11. <component :is="currentTabComponent.component" :name="currentTabComponent.code" v-bind="options"
  12. v-if="currentTabComponent" />
  13. </div>
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. import { PropType } from 'vue'
  18. import { useDynamicComponent } from '@/hooks/component'
  19. const props = defineProps({
  20. code: String,
  21. options: Object,
  22. // 组件内容方向
  23. direction: {
  24. type: String as PropType<'left' | 'right' | 'top' | 'bottom'>,
  25. default: 'top',
  26. },
  27. })
  28. const { dynamicComponents, currentTabComponent, componentChange } = useDynamicComponent(props.code);
  29. </script>
  30. <style lang="less">
  31. @import './index.less';
  32. </style>