{{HTMLRef}}
译者注: 本翻译的一些术语参考了Vuejs-中文页面。
HTML <slot> 元素 ,作为 Web Components 技术套件的一部分,是Web 组件内的一个占位符。该占位符可以在后期使用自己的标记语言填充,这样您就可以创建单独的 DOM 树,并将它与其它的组件组合在一起。
| Content categories | Flow content, phrasing content |
|---|---|
| Permitted content | Transparent |
| Events | {{event("slotchange")}} |
| Tag omission | {{no_tag_omission}} |
| Permitted parents | Any element that accepts phrasing content |
| Permitted ARIA roles | None |
| DOM interface | {{domxref("HTMLSlotElement")}} |
此元素有全局属性。
<template id="element-details-template">
<style>
details {font-family: "Open Sans Light", Helvetica, Arial, sans-serif }
.name {font-weight: bold; color: #217ac0; font-size: 120% }
h4 {
margin: 10px 0 -8px 0;
background: #217ac0;
color: white;
padding: 2px 6px;
border: 1px solid #cee9f9;
border-radius: 4px;
}
.attributes { margin-left: 22px; font-size: 90% }
.attributes p { margin-left: 16px; font-style: italic }
</style>
<details>
<summary>
<code class="name"><<slot name="element-name">NEED NAME</slot>></code>
<i class="desc"><slot name="description">NEED DESCRIPTION</slot></i>
</summary>
<div class="attributes">
<h4>Attributes</h4>
<slot name="attributes"><p>None</p></slot>
</div>
</details>
<hr>
</template>
Note: 您可以在 element-details (see it running live) 找到这个示例的完整演示版。另外,您也可以在Using templates and slots这里找到具体的解释。
| Specification | Status | Comments |
|---|---|---|
| {{SpecName('HTML WHATWG','scripting.html#the-slot-element','<slot>')}} | {{Spec2('HTML WHATWG')}} | |
| {{SpecName('DOM WHATWG','#shadow-tree-slots','Slots')}} | {{Spec2('DOM WHATWG')}} |
{{Compat("html.elements.slot")}}