[Vuejs]-Vue add content inside #document-fragment

0👍

I solved it by using a ref on the template tag and then the render-function.

<template id="some-id" ref="someRef">
</template>
const someRef: Ref<HTMLTemplateElement | undefined> = ref()
onMounted(() => {
  if (someRef.value?.content) {
    // @ts-ignore
    render('div', someRef.value.content)
  }
})

if you want to insert a component you can use the it like this:

const someRef: Ref<HTMLTemplateElement | undefined> = ref()
onMounted(() => {
  if (someRef.value?.content) {
    // @ts-ignore
    render(h(SomeComponent, { someProp: someValue }), someRef.value.content)
  }
})

Maybe there is a better, but for now that works.

Leave a comment