问题描述
我有一个自定义元素“ thing-y”,该元素使用template
和两个slot
。
<template id="thingy-template">
<details>
<summary><slot name="thing-id">THING</slot></summary>
<p><slot name="thing-content">VALUE</slot></p>
</details>
</template>
thing-y元素构造函数在阴影DOM中克隆模板
customElements.define('thing-y',class extends HTMLElement {
constructor() {
super();
const template = document
.getElementById('thingy-template')
.content;
this.attachShadow({mode: 'open'})
.appendChild(template.cloneNode(true));
}
});
然后在页面中的任意位置使用元素
<thing-y id="something">
<span slot="thing-id">Something</span>
<span slot="thing-content">42</span>
</thing-y>
到目前为止,很好。
现在,我想在slot
的两个地方使用相同的template
值,所以我将template
的定义更改为
<template id="thingy-template">
<details>
<summary><slot name="thing-id">THING</slot></summary>
<p><slot name="thing-id">THING</slot>
content is <slot name="thing-content">VALUE</slot></p>
</details>
</template>
如何实现这个简单的要求?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)