Reputation: 196
How should I use Vue 3 fragments with render functions? shouldn't the following code work?
import { h } from 'vue'
render () {
return [
h('label', { htmlFor: 'username' }, this.label),
h('input', { id: 'username' }),
]
},
Upvotes: 3
Views: 2607
Reputation: 1
Yes that syntax is correct for defining fragments in render functions :
import { h } from "vue";
export default {
props: ["label", "errors"],
render() {
return [
h("label", { htmlFor: "username" }, this.label),
h("input", { id: "username" }),
this.errors && h("span", { class: "red" }, this.errors)
];
}
};
this is equivalent to :
<template>
<label for="username"> {{this.label}}</label>
<input id="username" />
<span class="red" v-if="errors">{{errors}}</span>
</template>
Upvotes: 2