包装器和本机剃须刀组件之间的区别

时间:2019-04-04 10:18:45

标签: asp.net-core blazor blazor-server-side razor-components

我在blazor服务器端有一些说明。 blazor本机组件和包装器组件之间有什么区别?谁能帮我吗?

2 个答案:

答案 0 :(得分:2)

免责声明:我没有在使用blazor,但是自从首次介绍以来,它就使用了一点,但是我从未听说过本机和包装器组件nor does the documentation include this wording。因此,我可能是错的,但是从措辞上我可以理解,“包装”意味着互操作性。

我要引用this excelent blog post上的一些文字

可能是 native ,因为该组件仅由.NET bl(r)azor创建而没有javascript:

  

由于Razor组件将服务器端作为.NET Standard应用程序运行,因此逻辑是使用 .NET技术编写的。由于Blazor框架采用了RenderTree,这是可能的,该框架是DOM抽象,类似于流行的JavaScript框架(如Angular和React)中使用的虚拟DOM。让我们看一下框架的UI端,以了解如何编写组件。

<p>Current count: @currentCount</p>
<button class="btn btn-primary" onclick="@IncrementCount">
  Click me
</button>

@functions {
  int currentCount = 0;

  [Parameter] protected int CountBy { get; set; } = 1;

  void IncrementCount()
  {
    currentCount += CountBy;
  }
}

可能是包装器,因为我们在组件的互操作性层中使用了JS函数。

  

另外,Razor组件应用程序可以使用JavaScript生态系统的依赖关系,并且通过互操作性层,该应用程序可以与 .NET和JavaScript依赖关系进行双向通信。对于Razor组件不支持必要的浏览器/ DOM API或现有JavaScript库有用的情况,这很有用。

GeoLocation.cs(.NET)

public class Geolocation
{
  // ...

  public async Task GetCurrentPosition(
    Action<Position> onSuccess,
    Action<PositionError> onError,
    PositionOptions options = null)
  {
    OnGetPosition = onSuccess;
    OnGetPositionError = onError;
    await JSRuntime.Current.InvokeAsync<bool>(
      "interopGeolocation.getCurrentPosition",
      new DotNetObjectRef(this),
      options);
  }

  // ...
}

interopGeolocation.js(浏览器)

window.interopGeolocation = {
  getCurrentPosition: function (geolocationRef, options) {
    const success = (result) => {
      geolocationRef.invokeMethodAsync(
        'RaiseOnGetPosition',
        interopGeolocation.toSerializeable(result));
    };
    const error = (er) =>
    geolocationRef.invokeMethodAsync(
      'RaiseOnGetPositionError',
      er.code);
    navigator.geolocation.getCurrentPosition(
      success,
      error,
      options);
},

// ...

答案 1 :(得分:1)

  1. 包装器组件是React中使用的概念或模式。 Blazor中不存在此类模式。

  2. 服务器端Blazor和客户端端Blazor共享相同的组件模型。

  3. 本地剃刀?从来没有听说过Blazor的人使用此术语,但是如果您希望使用此术语来指代运行Web Assembly的客户端Blazor,请继续。我没问题。

  4. 让我介绍一个新术语: Blazor Components 。从来没有听说过Blazor的人至少使用(不是正式地)这个术语,但这在我看来是自然而适当的,尤其是因为 Razor Components 已过时,并且术语服务器端应当使用Blazor和客户端Blazor。

希望这对您有帮助...

相关问题