【问题标题】:Stenciljs how to check if slot is empty? [duplicate]Stenciljs如何检查插槽是否为空? [复制]
【发布时间】:2021-10-22 02:37:27
【问题描述】:

如何检查 slot 是否有值或为空?

这是我的代码:

  <div>
    <slot name="info"></slot>
  </div>

这是我需要的伪代码:

<div>

<slot name="info"></slot>

{this.info == null ? <p> No informations </p> : <p> {this.info.value} </p>}

</div>

【问题讨论】:

    标签: javascript typescript components stenciljs slot


    【解决方案1】:

    你可以获得对组件宿主元素的引用

    @Element() hostElement: HTMLStencilElement;
    

    并查询您的插槽

    this.hostElement.querySelector('[slot="slot1"]');
    

    如果是假的,则不存在

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 1970-01-01
      • 2019-01-11
      • 1970-01-01
      • 2011-07-02
      • 2018-07-03
      • 2013-02-07
      相关资源
      最近更新 更多