App.vue 890 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <script setup vapor lang="ts">
  2. import type { Component } from 'vue'
  3. const props = defineProps<{
  4. caseId: string
  5. }>()
  6. type CaseModule = { default: Component }
  7. const caseModules = import.meta.glob<CaseModule>('./cases/**/*.vue', {
  8. eager: true,
  9. })
  10. const moduleKey = `./cases/${props.caseId}.vue`
  11. const selectedCase = caseModules[moduleKey]
  12. if (!selectedCase) {
  13. const availableCases = Object.keys(caseModules)
  14. .map(path => path.slice('./cases/'.length, -'.vue'.length))
  15. .sort()
  16. .join(', ')
  17. throw new Error(
  18. `[transition] Unknown case "${props.caseId}". Available cases: ${availableCases}`,
  19. )
  20. }
  21. const currentCase = selectedCase.default
  22. </script>
  23. <template>
  24. <div class="transition-container">
  25. <component :is="currentCase" />
  26. </div>
  27. </template>
  28. <style>
  29. .transition-container > div {
  30. padding: 15px;
  31. border: 1px solid #f7f7f7;
  32. margin-top: 15px;
  33. }
  34. </style>