修复仪表盘页面主题切换无响应问题
- 在 ToggleDarkMode 方法中添加 StateHasChanged() 调用 - 在 OnInitializedAsync 方法中添加 StateHasChanged() 调用 - 确保在异步操作后 UI 能及时更新状态 - 解决 Blazor InteractiveServer 模式下的状态同步问题 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
449e4d1358
commit
5412b2d997
1 file changed
+4
@@ -55,6 +55,8 @@
|
||||
{
|
||||
// 从配置文件读取用户的主题偏好
|
||||
_isDarkMode = await UiPreferences.GetIsDarkModeAsync();
|
||||
// 确保初始化后 UI 能正确显示主题
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void ToggleDrawer()
|
||||
@@ -67,5 +69,7 @@
|
||||
_isDarkMode = !_isDarkMode;
|
||||
// 保存主题偏好到配置文件
|
||||
await UiPreferences.SetIsDarkModeAsync(_isDarkMode);
|
||||
// 强制刷新组件状态,确保在异步操作后 UI 能及时更新
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user