我尝试使用 Lit 2.0 构建复合组件,但将数据作为属性传递给插槽似乎是不可能的。
<my-accordion>
<my-accordion-title>Title</my-accordion-title>
<my-accordion-content>Content</my-accordion-content>
</my-accordion
如何将“扩展”属性传递给自定义元素插槽?
这是我的自定义元素:
@customElement("my-accordion")
export class MyAccordion extends LitElement {
@property()
extended: boolean = false;
toggleExtend(){
this.extended = !this.extended
}
render() {
return html`
<div @click=${this.toggleExtend}>
<slot .extended=${this.extended}></slot>
</div>
`;
}
}
@customElement("my-accordion-title")
export class MyAccordionTitle extends LitElement {
// want to access parent node extended property here
render() {
return html`
<div>
<slot></slot>
</div>
`;
}
}