Vue模板中渲染VNode
vue2
vue
<template>
<hello name="hello"></hello>
</template>
<script>
export default {
components: {
hello: {
props: {
name: String
},
render(h) {
return h('span', this.name)
}
}
},
}
</script>vue3
单个VNode
vue
<template>
<hello></hello>
</template>
<script setup>
import {h} from 'vue'
const hello = h('span', 'hello')
</script>多个VNode
vue
<template>
<component :is="hello"/>
</template>
<script setup>
import {h} from 'vue'
const hello = [
h('span', 'hello'),
h('span', 'hello1'),
h('span', 'hello2')
]
</script>