你可以通过在 nuxt.config.ts 中提供 colorMode 属性来配置该模块。以下是默认选项:
export default defineNuxtConfig({
modules: ['@nuxtjs/color-mode'],
colorMode: {
preference: 'system', // $colorMode.preference 的默认值
fallback: 'light', // 未检测到系统偏好时的回退值
globalName: '__NUXT_COLOR_MODE__',
componentName: 'ColorScheme',
classPrefix: '',
classSuffix: '',
storage: 'localStorage', // 或 'sessionStorage' 或 'cookie'
storageKey: 'nuxt-color-mode'
}
})
preferencestring'system'默认的颜色模式偏好。'system' 是一个特殊值,会根据系统偏好自动检测颜色模式。
fallbackstring'light'如果未检测到系统偏好,则使用的回退颜色模式值。
dataValuestringundefined可选的数据集属性,添加到 <html> 元素上。例如,如果设置 dataValue: 'theme',则会在 <html> 上添加 data-theme="dark"。这对于使用 daisyUI 等库时非常有用。
storage'localStorage' | 'sessionStorage' | 'cookie''localStorage'用于持久化颜色模式偏好的存储类型。
storageKeystring'nuxt-color-mode'存储的键名。