Fix init theme failed error (#217)
This commit is contained in:
1 parent
6edf940747
commit
37af52a3a2
5 files changed
+27
No files matched your search
@@ -14,6 +14,7 @@ import {
|
||||
initializeCookies,
|
||||
initializeDescription,
|
||||
initializeFavicon,
|
||||
initializeTheme,
|
||||
initializeToken,
|
||||
initializeUser,
|
||||
initializeKeywords,
|
||||
@@ -35,6 +36,7 @@ const main = async () => {
|
||||
|
||||
// non-async and no need to await
|
||||
initializeCurrency();
|
||||
initializeTheme();
|
||||
initializeExchangeRate();
|
||||
initializeTitle();
|
||||
initializeDescription();
|
||||
|
||||
@@ -7,3 +7,4 @@ export * from './login';
|
||||
export * from './site';
|
||||
export * from './price';
|
||||
export * from './application';
|
||||
export * from './theme';
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getCookie, setCookie } from 'typescript-cookie';
|
||||
import favicon from '@/assets/images/favicon.ico';
|
||||
import { getLocale } from '@/i18n';
|
||||
import { applyTheme } from './theme';
|
||||
import store from '@/store';
|
||||
import { IToken } from '@/models';
|
||||
import psl from 'psl';
|
||||
@@ -165,6 +166,15 @@ export const initializeToken = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize theme
|
||||
*/
|
||||
export const initializeTheme = async () => {
|
||||
const theme = getCookie('THEME') || 'light';
|
||||
console.debug('initialize theme', theme);
|
||||
applyTheme(theme);
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize user by token
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export function applyTheme(theme: string) {
|
||||
if (theme === 'dark') {
|
||||
document.documentElement.classList.add('dark');
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user