html - StencilJS:可选的 <slot/> 元素在 IE11/Edge 中不起作用

标签 html internet-explorer microsoft-edge web-component stenciljs

我用 StencilJS 写了一个网络组件。

开槽元素只应在特定情况下呈现。所以有一个可选元素。

<div>
  <slot name="title"/>
    {this.active && (<slot name="content"/>)}
</div>

Web组件的调用如下:

<my-test>
   <div slot="title">This is a test</div>
   <div slot="content">123</div>
</my-test>

这在 Microsoft Edge 和 IE11 中不起作用。对于 Chrome 和 Firefox,一切都很好。

我知道插槽不受支持:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot#Browser_compatibility

但显然在 stenciljs 中有一些 polyfill。

Chrome : Rendered in Chrome

IE11: Rendered in IE11

是否有关于该主题的经验?

最佳答案

作为变通方法,不是使插槽有条件(IE 不会尊重),而是有条件地隐藏插槽:

<div>
  <slot name="title"/>
  <div style={!this.active && { 'display': 'none' }}>
    <slot name="content"/>
  </div>
</div>

关于html - StencilJS:可选的 <slot/> 元素在 IE11/Edge 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56004891/

相关文章:

html - 段落的文本不会呈现在 float 图像下方,但段落本身会呈现

css - 如何在IE8中创建一个1px高度的div

html - 清除 Microsoft Edge 中输入类型日期的值

Javascript正则表达式从文本中获取元素

php - 如何在php中的一页中使用2个数据库连接

javascript - Bootstrap Datepicker 未加载

javascript - 如何禁用悬停在按钮上时显示的默认 URl

.net - 从 Internet Explorer 访问硬件

c# - 在新的 Microsoft Edge 窗口中打开 URL

javascript - 由于错误 c004e005,无法完成操作