【发布时间】:2019-10-19 18:55:31
【问题描述】:
我有一个 Blazor 应用程序,在 OnAfterRenderAsync 中,我正在调用一个需要调用 JavaScript 方法的方法 PlayVideo()。在以前版本的 Blazor 中,我能够检查 context.IsConnected 属性以确保我可以进行 JavaScript 调用。但是,在最新版本的 Blazor 中,此属性已被删除。现在,当我尝试从 PlayVideo() 方法进行 JavaScript 调用时,我收到以下错误消息:
JavaScript interop calls cannot be issued at this time. This is because the component is being prerendered and the page has not yet loaded in the browser or because the circuit is currently disconnected. Components must wrap any JavaScript interop calls in conditional logic to ensure those interop calls are not attempted during prerendering or while the client is disconnected.
根据我的阅读,从 OnAfterRenderAsync 方法调用 JavaScript 应该可以正常工作,因为它应该已连接。自从 context.IsConnected 属性被删除后,有没有办法检查我是否可以进行 JavaScript 调用?
谢谢你
【问题讨论】:
标签: javascript c# blazor-server-side