【发布时间】:2020-06-23 19:09:03
【问题描述】:
我想在用户进入 Dashboard 页面后,ISessionStorageService 正常工作时获取当前使用登录信息,Dashboard 有一个 layout布局页面获取SessionStorage当前用户登录的值,
布局页面
h1>@UserInfo.FullName</h1>
@Body
@code {
private LoginUser UserInfo = new LoginUser();
async Task UpdateUserInfo() => UserInfo = await SessionStorage.GetItemAsync<LoginUser>("LoginUser");
protected override async Task OnInitializedAsync()
{
await UpdateUserInfo();
}
}
登录页面设置值
await SessionStorage.SetItemAsync("LoginUser", loginUser);
注意:用户登录和页面之间的切换可以工作,但是当我想刷新页面时会报错
InvalidOperationException: JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendererd. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.
【问题讨论】:
-
你不能在那个事件上做 js 互操作,试试OnAfterRenderAsync 就像错误提到的那样。
-
你的意思是调用'OnAfterRenderAsync'?当我打电话给
OnAfterRenderAsyncuserInfo 是空的
标签: c# .net-core blazor blazor-server-side session-storage