How should I use Vue 3 fragments with render functions? shouldn’t the following code work?
JavaScript
x
9
1
import { h } from 'vue'
2
3
render () {
4
return [
5
h('label', { htmlFor: 'username' }, this.label),
6
h('input', { id: 'username' }),
7
]
8
},
9
Advertisement
Answer
Yes that syntax is correct for defining fragments in render functions :
JavaScript
1
14
14
1
import { h } from "vue";
2
export default {
3
props: ["label", "errors"],
4
5
render() {
6
return [
7
h("label", { htmlFor: "username" }, this.label),
8
h("input", { id: "username" }),
9
this.errors && h("span", { class: "red" }, this.errors)
10
];
11
}
12
};
13
14
this is equivalent to :
JavaScript
1
6
1
<template>
2
<label for="username"> {{this.label}}</label>
3
<input id="username" />
4
<span class="red" v-if="errors">{{errors}}</span>
5
</template>
6