Web组件 - 每个插槽的多个元素
我正在研究新的网络组件,并遇到了有关插槽的一些问题。
我的外部容器组件内部有一个“主槽”,其中多个元素应插入(中)。但是,只能添加每个命名插槽的一个元素。
我的问题:有没有办法将多个元素添加到一个名称插槽中?如下所示:
<own-container>
<own-element slot="main"></own-element>
<own-element slot="main"></own-element>
<own-element slot="main"></own-element>
<own-element slot="main"></own-element>
</own-container>
I'm working on new web-components and ran into some issues concerning slots.
I have an outer container-component with a "main-slot" inside, in which multiple elements should be inserted (into the same slot). However, it is only possible to add one element per named slot.
My question: is there a way to add multiple elements to one named slot? Like shown here:
<own-container>
<own-element slot="main"></own-element>
<own-element slot="main"></own-element>
<own-element slot="main"></own-element>
<own-element slot="main"></own-element>
</own-container>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还有 comestative&lt; slot&gt;
您可以在一个Web组件上获得命名 lots或命令插槽,
以模拟名为
&lt; slot&lt; slot&gt;
,将内容分配给同一命名&lt; slot&gt;
可能需要“ nofollow noreferrer”> mutation obserer observer api api
附加
您 每个插槽元素:
There is also imperative <slot>
But! you get Named slots OR Imperative slots, on one Web Component
To mimic named
<slot>
, assigning content to the same named<slot>
you probably need the Mutation Observer API
addendum
You can have multiple elements per slot:
没有。命名插槽不可能。诀窍是要有包装器
div
元素来包装您的Lightdom
。如果存在其他
div
导致样式问题,则可以使用新的内容
显示框的类型。一个元素的孩子看起来像是元素父母的直接子女,而忽略了元素本身。但是,请注意,它可能导致可访问性问题。
Nope. It is not possible for named slot. The trick is to have a wrapper
div
element to wrap yourlightDOM
.If the presence of additional
div
causes styling problem, then you can use newcontents
type of display box.The
display: contents
causes an element's children to appear as if they were direct children of the element's parent, ignoring the element itself. However, note that it can cause accessibility issues.