这是我想做的事情的示例:
父组件
<MyChildComponent ParamList="{hello, world, this is great}"/>
子组件
<ol>
@foreach(string myParam in ParamList)
{
<li>@myParam</li>
}
</ol>
@code {
[Parameter]
public List<string> ParamList {get;set;}
}
预期输出
1. Hello
2. World
3. this is great
我觉得我做错了什么,因为我在 blazor 文档中找不到有关执行此操作的任何内容。我指的不是泼溅。
最佳答案
您可以通过多种方式做到这一点。这是一个:
MyChildComponent.razor
<ol>
@foreach (string myParam in ParamList)
{
<li>@myParam</li>
}
</ol>
@code {
[Parameter]
public IReadOnlyList<string> ParamList { get; set; }
}
用法
<MyChildComponent ParamList="list" />
@code{
List<string> list = new List<string> {"hello", "world", "Angular is great"};
}
关于blazor - 如何将 List<string> 作为参数传递给 blazor 中的子组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59916846/