fix(theme): page should be in light mode while printing, close #502 (#503)

This commit is contained in:
pengzhanbo 2025-03-02 00:07:39 +08:00 committed by GitHub
parent 00a858761c
commit d4e76e0b0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,5 @@
import type { App, InjectionKey, Ref } from 'vue' import type { App, InjectionKey, Ref } from 'vue'
import { useDark } from '@vueuse/core' import { useDark, useEventListener } from '@vueuse/core'
import { inject, ref } from 'vue' import { inject, ref } from 'vue'
import { useThemeData } from './theme-data.js' import { useThemeData } from './theme-data.js'
@ -50,6 +50,16 @@ export function setupDarkMode(app: App): void {
Object.defineProperty(app.config.globalProperties, '$isDark', { Object.defineProperty(app.config.globalProperties, '$isDark', {
get: () => isDark, get: () => isDark,
}) })
useEventListener('beforeprint', () => {
if (isDark.value)
document.documentElement.dataset.theme = 'light'
})
useEventListener('afterprint', () => {
if (isDark.value)
document.documentElement.dataset.theme = 'dark'
})
} }
/** /**