fix: auto mode error

This commit is contained in:
Uyarn 2021-12-23 01:29:06 +08:00 committed by uyarnchen
parent 658fad2898
commit 8ab5ec409f
2 changed files with 17363 additions and 1 deletions

17361
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -74,7 +74,7 @@ const actions = {
}, },
async changeMode({ commit, state }, payload: IStateType) { async changeMode({ commit, state }, payload: IStateType) {
let theme = payload.mode; let theme = payload.mode;
const isDarkMode = theme === 'dark';
if (payload.mode === 'auto') { if (payload.mode === 'auto') {
const media = window.matchMedia('(prefers-color-scheme:dark)'); const media = window.matchMedia('(prefers-color-scheme:dark)');
if (media.matches) { if (media.matches) {
@ -83,6 +83,7 @@ const actions = {
theme = 'light'; theme = 'light';
} }
} }
const isDarkMode = theme === 'dark';
if (theme !== state.mode) { if (theme !== state.mode) {
document.documentElement.setAttribute('theme-mode', isDarkMode ? 'dark' : ''); document.documentElement.setAttribute('theme-mode', isDarkMode ? 'dark' : '');
} }