在没有额外包装标签的情况下,如何在Vue 3 <script setup>
环境中使用VUE的v-html
指令?
我希望能够做这样的事情:
<script setup>
const html = ref(`<pre></pre>`)
</script>
<template v-html="html"></template>
在没有额外包装标签的情况下,如何在Vue 3 <script setup>
环境中使用VUE的v-html
指令?
我希望能够做这样的事情:
<script setup>
const html = ref(`<pre></pre>`)
</script>
<template v-html="html"></template>
使用渲染功能来制作功能组件.直接插入或与<component>
一起插入.您甚至可以在不使用<component>
的情况下动态更改它,或者您可以更改呈现函数以发出不同的HTML:
<script setup>
import {h, ref} from 'vue';
const dynamic = ref(() => h('pre', {}, 'i am dynamic'));
</script>
<template>
<div>
<component :is="() => h('pre', {}, 'i am a static PRE without a wrapper')"/>
<dynamic />
</div>
<button @click="dynamic = () => h('input', {value: 'i was PRE'})">Change to INPUT</button>
</template>