ruby-on-rails - 如何使用 vueonrails 对嵌套组件或开槽内容进行 SSR?
问题描述
我正在尝试使用 Hypernova 和vueonrails
助手将 Vue.js 组件添加到具有 SSR 支持的 Ruby-on-Rails 应用程序中。
我可以.html.erb
使用这个助手从视图 () 中使用 Hypernova 渲染已注册的组件:
<%= render_vue_component('HelloWorld', message: 'Hello World from SSR!') %>
假设我的HelloWorld
组件<slot>
在其模板中有一个:
<template>
<div class="helloworld">
<h1>{{ message }}</div>
<slot></slot>
</div>
</template>
我想在.html.erb
using中复制类似以下内容render_vue_component
:
<hello-world message="Hello World from SSR!">
<hello-world>SSR Nested component</hello-world>
</hello-world>
我如何将子元素传递给render_vue_component
助手,以便它们由 Hypernova 渲染?
解决方案
好吧,我分析了 repo 并通过查看它,我认为您应该使用render_vue_component
only 来渲染根组件,例如当您使用@vue/climain.js
启动项目时:
<%= render_vue_component('App', { router }) %>
我通过分析vueonrails源码得出了这个结论。
如果你查看render_vue_component 函数,它只需要标识符和一个数据对象,它在内部调用render_react_component
.
通过这个签名,它根本不适合Vue 的渲染函数签名,即(element, children)
或(element, attributes, children)
.
也许您通过在 repo 上打开一个问题来找到更好的支持。
但是在使用这个项目之前我会三思而后行,因为到目前为止还没有任何文档并且检查网站,似乎他们更专注于销售有关该项目的书籍而不是创建文档。
推荐阅读
- arm - 直接从汇编语言访问性能计数器的 ARMv7 指令
- dynamic-programming - 目标总和 [leetcode] 通过分配符号计算具有给定目标总和的子集
- mongodb - 删除没有内容的记录
- javascript - Angular Typescript:Swagger CodeGen Generator 使所有类属性为 Nullable
- java - 使用 Java 查找区域的标准时间名称
- python - Dask Dataframe 高效行对生成器?
- chromium - 无头铬 - 在从命令行打印到 pdf 之前解析 javascript
- python - 为 Python 编写了二进制搜索算法,包括递归和迭代版本。你如何判断他们的效率?
- python - 饼图的查询集
- c# - 在 linq join 中合并等于