Blazor - SetParameters - 为什么字符串参数绑定的行为与复杂类型不同 [英] Blazor - SetParameters - why string parameter binding behaves differently from a complex type

查看:28
本文介绍了Blazor - SetParameters - 为什么字符串参数绑定的行为与复杂类型不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑带有字符串参数和复杂类型参数的子组件.

Consider child component with string parameter and with a complex type parameter.

<Child Name="@strProperty" />
<Child Model="@compelexType" />

假设两个参数都没有改变,在父组件上调用 StateHasChanged 会导致具有复杂参数的子组件重新渲染,但不会重新渲染字符串参数.

Assuming neither parameter has changed, calling StateHasChanged on the parent component causes the Child component with complex parameter to rerender, but not with string parameter.

查看此演示:https://blazorrepl.com/repl/wbYguGuA515uMYR742

你如何解释不同的行为?

How do you explain different behavior?

推荐答案

文档:

继承自 ComponentBase如果满足以下任一条件,则跳过由于参数更新而导致的重新渲染:

Components inherited from ComponentBase skip rerenders due to parameter updates if either of the following are true:

  • 所有参数值都是已知的不可变原始类型,例如intstring>、DateTime自上一组参数设置以来没有改变.
  • 组件的ShouldRender 方法返回 false.
  • All of the parameter values are of known immutable primitive types, such as int, string, DateTime, and haven't changed since the previous set of parameters were set.
  • The component's ShouldRender method returns false.

这篇关于Blazor - SetParameters - 为什么字符串参数绑定的行为与复杂类型不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆