StackBlitzEmbed.vue 981 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script setup lang="ts">
  2. import type { EmbedOptions } from '@stackblitz/sdk'
  3. import sdk from '@stackblitz/sdk'
  4. import { ref, watch } from 'vue'
  5. const props = withDefaults(
  6. defineProps<{
  7. projectId: string
  8. options: EmbedOptions
  9. }>(),
  10. {
  11. options: {
  12. openFile: 'src/components/TheExperience.vue',
  13. view: 'preview',
  14. forceEmbedLayout: true,
  15. hideExplorer: true,
  16. hideNavigation: true,
  17. },
  18. },
  19. )
  20. const embed = ref(null)
  21. const isSnippetLoaded = ref(false)
  22. watch(
  23. () => embed.value,
  24. (value) => {
  25. if (value) {
  26. sdk.embedProjectId(value, props.projectId, props.options)
  27. }
  28. },
  29. )
  30. </script>
  31. <template>
  32. <div
  33. ref="embed"
  34. class="stackblitz-embed"
  35. >
  36. <div
  37. v-if="!isSnippetLoaded"
  38. class="text-gray-500 text-2xl"
  39. >
  40. Loading...
  41. </div>
  42. </div>
  43. </template>
  44. <style>
  45. .stackblitz-embed {
  46. margin: 2rem 0;
  47. border-radius: 8px;
  48. overflow: hidden;
  49. border: none;
  50. min-height: 500px;
  51. }
  52. </style>