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' }),
]
},
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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.