繁体   English   中英

使用 Vue.js 3 个片段渲染 function

[英]Use Vue.js 3 fragments with render function

我应该如何使用具有渲染功能的 Vue 3 片段? 下面的代码不应该工作吗?

import { h } from 'vue'

render () {
  return [
    h('label', { htmlFor: 'username' }, this.label),
    h('input', { id: 'username' }),
  ]
},

是的,在渲染函数中定义片段的语法是正确的:

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)
    ];
  }
};

这相当于:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM