最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to query children of Lit-element shadow root using tag name - Stack Overflow

programmeradmin0浏览0评论

Is there is a way to get a child lit-element (by its name) in the host? I only know how to access them using id and this.shadowRoot.getElementById()

import { LitElement, html } from 'lit-element';
import './child-element.js';

class ParentElement extends LitElement {
  render() {
    return html`<child-element someattribute="somevalue"></child-element>`;
  }
}

Is there is a way to get a child lit-element (by its name) in the host? I only know how to access them using id and this.shadowRoot.getElementById()

import { LitElement, html } from 'lit-element';
import './child-element.js';

class ParentElement extends LitElement {
  render() {
    return html`<child-element someattribute="somevalue"></child-element>`;
  }
}
Share Improve this question edited Apr 2, 2019 at 3:53 Nomad asked Apr 1, 2019 at 18:48 NomadNomad 4296 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Turns out it was simply calling shadowRoot.querySelector("element-name"):

...
class ParentElement extends LitElement {
  render() {
    return html`<child-element someattribute="somevalue"></child-element>`;
  }
  aMethod() {
    let childElement = this.shadowRoot.querySelector("child-element");
  }
}
...
发布评论

评论列表(0)

  1. 暂无评论