我在select.cs中插入了一个参数bool,并在剃须刀页面中将其值设置为true,但它总是返回false。
select.cs
public class NameSelect<TItemValue> : CachedSelect<TItemValue, AgLookupDto>
{
[Parameter]
public bool Proceed { get; set; }
public NameSelect()
{
if (typeof(TItemValue) == typeof(string))
ValueName = nameof(AgLookupDto.Code);
else
ValueName = nameof(AgLookupDto.Id);
LabelName = nameof(AgLookupDto.Code);
Console.WriteLine(Proceed);
}}
在Page.razor中
<AntDesign.Col Md="5" Xs="24">
<FormItem Label="Ag">
<NameSelect @bind-Value="@context.AgId" Item="@context.Ag" Proceed="true">
</NameSelect>
</FormItem>
</AntDesign.Col>
发布于 2022-08-01 07:28:58
此部分是一个构造函数:
public NameSelect()
{
...
Console.WriteLine(Proceed);
}
在Blazor组件中,我们通常不使用构造函数。
当您使用它们时,它们在框架可以设置参数之前执行,在DI可以执行属性注入之前执行。所以您的WriteLine()只是运行得太早了。
这里的代码将在OnInitialized()和/或OnParametersSet()中正常工作。
https://stackoverflow.com/questions/73189688
复制相似问题