你可以在 Vue 模板中渲染 VNodes 吗?

编程入门 行业动态 更新时间:2024-10-10 21:26:13
本文介绍了你可以在 Vue 模板中渲染 VNodes 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个渲染函数将一些数据传递到作用域槽的情况.作为此数据的一部分,我想包括一些由渲染函数构造的 VNode,这些 VNode 可以选择由作用域插槽使用.在模板中写入作用域插槽以输出接收到的原始 VNode 时,是否有任何办法?

解决方案

您可以使用功能组件为模板的该部分渲染 vnode:

<div slot-scope="{ vnodes }"><vnodes :vnodes="vnodes"/>

</某些组件>

组件:{虚拟节点:{功能:真实,渲染:(h, ctx) =>ctx.props.vnodes}}

I have an situation where I have a render function that passes some data to a scoped slot. As part of this data I'd like to include some VNodes constructed by the render function that could optionally be used by the scoped slot. Is there anyway when writing the scoped slot in a template to output the raw VNodes that were received?

解决方案

You can use a functional component to render the vnodes for that section of your template:

<some-component>
  <div slot-scope="{ vnodes }">
    <vnodes :vnodes="vnodes"/>
  </div>
</some-component>

components: {
  Vnodes: {
    functional: true,
    render: (h, ctx) => ctx.props.vnodes
  }
}

这篇关于你可以在 Vue 模板中渲染 VNodes 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 02:29:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1146369.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:你可以   模板   Vue   VNodes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!