开关

一种允许用户在选中与未选中状态之间切换的控件。

安装

pnpm dlx shadcn-vue@latest add switch

用法

vue
<script setup lang="ts">
import { Switch } from '@/components/ui/switch'
</script>

<template>
  <Switch />
</template>

在开关滑块内添加图标

vue
<template>
  <Switch :model-value="isDark" @update:model-value="toggleTheme">
    <template #thumb>
      <Icon v-if="isDark" icon="lucide:moon" class="size-3" />
      <Icon v-else icon="lucide:sun" class="size-3" />
    </template>
  </Switch>
</template>

示例

表单

Email Notifications

Receive emails about new products, features, and more.

Receive emails about your account security.

Edit this page on GitHub