html - StencilJS:可选元素在 IE11/Edge 中不起作用
问题描述
我用 StencilJS 编写了一个 Web 组件。
开槽元素仅应在特定情况下呈现。所以有一个可选元素。
<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。
有没有关于该主题的经验?
解决方案
作为一种解决方法,不是使插槽有条件(IE 不会尊重),而是有条件地隐藏插槽:
<div>
<slot name="title"/>
<div style={!this.active && { 'display': 'none' }}>
<slot name="content"/>
</div>
</div>
推荐阅读
- angular - Angular App 未编译
- javascript - 即使状态为 200,JS 文件也不会在网络选项卡上显示内容
- java - Java <-> Angular Dto
- javascript - 使用 node.js 从 Spring Boot 2 响应中读取传入的 HTTPS 标头
- javascript - 如何在 PHP laravel 或 Java Script 中比较 3 个不同的数组
- javascript - 在 Javascript 中为几乎相同的输入获取不同的 typeof
- c++ - 如何在 C++ 中为 copy_if 等定义“一元谓词”?
- scala - 错误:未知参数“idea-shell”
- c# - 如何使用 serialPort DatatReceived 事件更改 tabControl 中的活动选项卡?
- asp.net - 将点击事件添加到日历内的动态按钮