Use v-html without extra wrapping tag with script setup #9926
Unanswered
dbzx10299
asked this question in
Help/Questions
Replies: 1 comment
-
have you try using <template>
<ClientOnly>
<component :is="tagName" v-html="content"> </component>
</ClientOnly>
</template>
<script setup lang="ts">
const html = ref("<pre><code>let a = 'foo';</code></pre>");
const tagName = computed(() => {
const arr = [...html.value.matchAll(/<([a-zA-Z]*)\b[^>]*>(.*?)<\/\1>/g)];
return arr.length >= 1 ? arr[0][1] : 'div';
});
const content = computed(() => {
return html.value.replace(/<([a-z]+)(?![^>]*\/>)[^>]*>/, '').replace(/<\/([a-z]+)>$/, '');
});
</script> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
How can I use vue's v-html directive in a Vue 3 <script setup> environment without an extra wrapping tag?
I want to be able to do something like this:
This code does work, but a 2-3 second delay can be observed when this approach is taken which is not ideal.
Is there a way we could create some kind of fragment component?
Beta Was this translation helpful? Give feedback.
All reactions