颜色模式开关

SwitchGitHub
一个用于在浅色和深色模式之间切换的开关。

用法

ColorModeSwitch 组件扩展了 Switch 组件,因此您可以传递任何属性,例如 colorsize 等。

<template>
  <UColorModeSwitch />
</template>

示例

使用自定义图标

使用 app.config.ts 通过 ui.icons 属性来自定义图标。

app.config.ts
export default defineAppConfig({
  ui: {
    icons: {
      light: 'i-ph-sun',
      dark: 'i-ph-moon'
    }
  }
})

使用 vite.config.ts 通过 ui.icons 属性来自定义图标。

vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        icons: {
          light: 'i-ph-sun',
          dark: 'i-ph-moon'
        }
      }
    })
  ]
})

API

属性

属性默认值类型
as'div'any

此组件应渲染为的元素或组件。

color'primary'"primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral"
namestring

字段的名称。作为名称/值对的一部分随其所属表单提交。

loadingboolean

当为 true 时,将显示加载图标。

尺寸'md'"md" | "xs" | "sm" | "lg" | "xl"
autofocusfalse | true | "true" | "false"
disabledboolean

当为 true 时,阻止用户与开关交互。

labelstring
loadingIconappConfig.ui.icons.loadingany

loading prop 为 true 时显示的图标。

defaultValueboolean

开关在初次渲染时的状态。当您不需要控制其状态时使用。

requiredboolean

当为 true 时,表示用户必须在提交所属表单之前设置值。

idstring
valuestring

当与 name 一起提交时,作为数据给定的值。

descriptionstring
ui{ root?: ClassNameValue; base?: ClassNameValue; container?: ClassNameValue; thumb?: ClassNameValue; icon?: ClassNameValue; wrapper?: ClassNameValue; label?: ClassNameValue; description?: ClassNameValue; }

更新日志

5b177— feat: 扩展原生 HTML 属性 (#5348)

5cb65— 特性:导入 @nuxt/ui-pro 组件