【发布时间】:2020-07-09 02:29:07
【问题描述】:
lit-element 文档描述了通过 (condition ? a : b) 进行的条件渲染。我想知道如何使用它来呈现多个页面之一,f.e.结合来自 Google 材料 Web 组件的 mwc-tab-bar。
我目前的解决方案是这样的:
render() {
... other stuff ...
${this.selectedPage === 0 ? html`
<div>
...
</div>
` : html``}
${this.selectedPage === 1 ? html`
<div>
...
</div>
` : html``}
... further pages ...
}
我不喜欢 :html`` 部分,但这就是它的本意吗?
【问题讨论】:
-
对我自己的问题的简短评论:在某些情况下,您可能不想交替呈现页面,而只隐藏除选定页面之外的所有页面。对于这种情况,可以像这样使用 hidden 属性:
标签: lit-element