[英]Use Vue.js 3 fragments with render function
How should I use Vue 3 fragments with render functions?我应该如何使用具有渲染功能的 Vue 3 片段? 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.