从父组件传递到子组件
子组件ChildComponent.razor:
<p>@i</p>
@code{
[Parameter]
public int i{get;set;}
父组件FatherComponent.razor:
<ChildComponent i=3>
</ChildComponent>
相当于调用子组件时给他相应的参数。
值得注意的是,上面传递的参数是值类型的,如果是引用类型,那么在子组件中的修改,对于父组件中的变量同样有效。但是,在子组件中对参数的修改不会马上反映到父组件UI的渲染上,如果要让父组件立刻反映出变化,需要使用回调,在父组件中触发StateHasChanged()。