1
0

StackBlitzEmbed.vue 913 B

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