Pinia Store,用于管理应用程序的亮/暗主题模式。
该 Store 会自动同步主题状态到 `` 元素的 class 列表,并支持持久化。
- Source:
Methods
(inner) initTheme() → {void}
初始化主题模式。
如果 `localStorage` 中没有 'theme' 的值,则会检查用户的系统颜色偏好( prefers-color-scheme: dark )来设置初始主题。
如果 `persist: true` 已启用,此函数通常会在 Pinia 恢复状态后运行。
- Source:
Returns:
- Type
- void
(inner) toggleTheme() → {void}
切换 `isDarkMode` 状态。
如果当前是亮模式,则切换到暗模式;反之亦然。
- Source:
Returns:
- Type
- void
(inner) useThemeStore() → {Object}
Pinia Store,用于管理应用程序的亮/暗主题模式。
它可以检测系统偏好,支持手动切换主题,并持久化主题状态。
Properties:
Name | Type | Description |
---|---|---|
isDarkMode |
Ref.<boolean> | 响应式布尔值,表示当前是否处于黑暗模式。 |
toggleTheme |
function | 切换 `isDarkMode` 状态的函数。 |
initTheme |
function | 初始化主题模式的函数,会检查 localStorage 和系统偏好。 |
- Source:
Returns:
- Type
- Object