✨ 升级到Nuxt4
✨ 完成分类 标签的HTML搭建 🐛 修复ssg相关配置 之前错误的使用了SPA 🐛 修复部分ssg兼容问题
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
const getInitialMode = () => {
|
||||
function getInitialMode(): 'light' | 'dark' {
|
||||
if (typeof window !== 'undefined') {
|
||||
// 优先用 html 的 class
|
||||
if (document.documentElement.classList.contains('dark')) return 'dark';
|
||||
if (document.documentElement.classList.contains('light')) return 'light';
|
||||
// 其次用 localStorage
|
||||
return localStorage.getItem('system-theme-mode') || 'light';
|
||||
const val = localStorage.getItem('system-theme-mode');
|
||||
if (!!val || (val !== 'light' && val !== 'dark'))
|
||||
return 'light';
|
||||
return val;
|
||||
}
|
||||
return 'light'; // SSR 默认
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user