返回 slidev
ShadowRoot.vue
根目录 / packages / client / internals / ShadowRoot.vue
1 <script setup lang="ts">
2 import { computed, ref, watchEffect } from 'vue'
3
4 const props = defineProps<{
5 innerHtml: string
6 }>()
7
8 const emit = defineEmits<{
9 (event: 'shadow', div: ShadowRoot): void
10 }>()
11
12 const el = ref<HTMLDivElement>()
13 const shadow = computed(() => el.value
14 ? (el.value.shadowRoot || el.value.attachShadow({ mode: 'open' }))
15 : null)
16 watchEffect(() => {
17 if (shadow.value && props.innerHtml) {
18 emit('shadow', shadow.value)
19 shadow.value.innerHTML = props.innerHtml
20 }
21 })
22 </script>
23
24 <template>
25 <div ref="el" />
26 </template>
27
27 lines Plain Text