无法从 Blazor 服务器应用程序中的新电路调用 JSInterop

时间:2021-07-28 16:45:56

标签: asp.net-core blazor blazor-jsinterop

我无法在打开新电路后调用 JSInterop 方法。我正在通过从 JS 中打开一个新选项卡来创建新电路,如下所示: await _jsRuntime.InvokeAsync<object>("open", "/new-tab", "_blank");

接下来,在我在新选项卡中呈现的组件中,我尝试调用这样的 JS 方法:

protected override async Task OnAfterRenderAsync(bool firstRender) {
    if (firstRender)
        await jsRuntime.InvokeVoidAsync("myJSmethod");
} 

一旦调用 jsRuntime,我就会收到以下错误:

The connection to ws://localhost:53216/myapp/ was interrupted while the page was loading.
dotnet-watch reload socket error.
> error { target: WebSocket, isTrusted: true, srcElement: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, 
composed: false, ... }
dotnet-watch reload socket closed.

感谢任何帮助或建议!

0 个答案:

没有答案