如何在模板中正确解析子组件。
我正在尝试使用Scencen.js来创建具有以下结构的选项卡组件:
<custom-tabs>
<custom-tab active label="Label 1">
Some generic HTML content <custom-rating value="4"></custom-rating>
</custom-tab>
<custom-tab active label="Label 2">
Some more generic HTML content <custom-rating value="5"></custom-rating>
</custom-tab>
</custom-tabs>
父组件需要通过解析每个“自定义标签”组件(没有渲染方法)来渲染基础HTML并提取'Label '来自每个选项卡的参数,构建这些标签的导航列表,并类似地提取每个选项卡的主要内容并显示在选项卡的相应面板中。
在我的父组件中,我在“ componentwillload”钩中获取选项卡
componentWillLoad() {
// Grab tabs from this component
this.tabs = Array.from(this.el.querySelectorAll('custom-tab'));
console.log(this.tabs);
}
,然后在渲染函数中我尝试输出内容:
return (
<div>
{this.tabs.map((tab: HTMLCustomTabElement, index: number) => {
return (
<div
role="tab"
onClick={() => this.openTab(index)}>
{tab.label} {tab.innerHTML}
</div>
);
})}
</div>
);
问题是tab.innerhtml
没有解析自定义评分< /code>组件,然后将其作为文本输出。您能否提出正确显示标签内容的正确方法,以使所有内容都正确解析?
I am trying to use Stencil.js to create tabs component with the following structure:
<custom-tabs>
<custom-tab active label="Label 1">
Some generic HTML content <custom-rating value="4"></custom-rating>
</custom-tab>
<custom-tab active label="Label 2">
Some more generic HTML content <custom-rating value="5"></custom-rating>
</custom-tab>
</custom-tabs>
The parent component needs to render the underlying HTML by parsing each 'custom-tab' component (which doesn't have the render method) and extracting the 'label' parameter from each tab, building the navigation list of those labels and similarly extracting the main content of the each tab and displaying in in the corresponding panel of the tab.
In my parent component I grab the tabs in the 'componentWillLoad' hook
componentWillLoad() {
// Grab tabs from this component
this.tabs = Array.from(this.el.querySelectorAll('custom-tab'));
console.log(this.tabs);
}
and then in render function I try to output the contents:
return (
<div>
{this.tabs.map((tab: HTMLCustomTabElement, index: number) => {
return (
<div
role="tab"
onClick={() => this.openTab(index)}>
{tab.label} {tab.innerHTML}
</div>
);
})}
</div>
);
The problem is tab.innerHTML
is not parsing the custom-rating
component and just outputs it as text. Could you please suggest the right way to display the tab's content so that everything is parsed properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过设置
innerhtml
:You can output HTML by setting the
innerHTML
property: