【发布时间】:2021-12-21 06:10:19
【问题描述】:
我希望能够以声明方式将 blazor 组件列表作为参数。
组件 1:
@foreach(Component2 input in Inputs)
{
@input
}
@code{
[Parameter]
public List<Component2> Inputs {get; set;}
}
组件 2:
<h1>@Header</h1>
@code{
[Parameter]
public string Header {get; set;}
}
我想如何使用它:
<Component1>
<Inputs>
<Component2 Header="hello" />
<Component2 Header="world" />
</Inputs>
</Component1>
有谁知道这是否可行?
谢谢你, 特拉维斯
【问题讨论】:
-
Blazor 不是 WinForms。您不拥有(创建)组件。
-
这不是 Blazor 模式。您可以构建自己的渲染树,但尽可能避免使用它。尤其如此,因为有一种更简单、更清洁的方法可以实现相同的输出。