Dark mode
Less than 1 minute
The theme supports dark mode and allows you to customize it.
Options
You can config dark mode through darkmode
in theme options.
import { hopeTheme } from "vuepress-theme-hope";
export default {
theme: hopeTheme({
darkmode: "switch", // or "toggle", "auto", "enable", "disable"
}),
};
Available options:
"switch"
: switch between dark, light and auto (default)"toggle"
: toggle between light mode and dark mode"auto"
: Automatically decide whether to apply dark mode based on user device's color-scheme or current time"enable"
: only dark mode"disable"
: disable dark mode
Try it
Toggle the button to see effects:
Getting Status
In Markdown files or Vue Template, you can access
$isDarkMode
to get dark mode status directly.In scripts, you can import
useDarkMode
from@vuepress/helper/client
to get dark mode status:import {
useDarkMode} from "@vuepress/helper/client"; constisDarkMode=useDarkMode();console.log(isDarkMode.value); // get dark mode statusIf
@vuepress/helper
is not installed, you should install it first:pnpmpnpm add -D @vuepress/helper@next
yarnyarn add -D @vuepress/helper@next
npmnpm i -D @vuepress/helper@next
Changelog
2/18/25, 7:08 AM
View All Changelog
b1230
-ona0268
-onba382
-on93385
-on2c32a
-on6d493
-one788a
-onb41c0
-ond72d7
-on54c46
-on1ba82
-on2a306
-on8174c
-onf5b66
-on79ac6
-on2243a
-on98f84
-on2c32c
-on3dac6
-on2fa50
-on55cc9
-on9856d
-onc540c
-onf18b7
-onfd395
-on1eb77
-onbcf02
-on60053
-on0c093
-on62d19
-onf6ff0
-on3c199
-on