본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Switch

원문 보기 위키 갱신

Switch (스위치)

옵션을 켜거나 끌 때 사용하는 스위치 컴포넌트예요. 설정 토글에 가장 많이 쓰이죠.

출처: 문서

본문

소개

옵션을 켜거나 끌 때 사용해요.

설치

import { createApp } from 'vue'
import { Switch } from '@nutui/nutui'

const app = createApp()
app.use(Switch)

기본 사용법

demo: switch basic

비활성 상태

demo: switch disabled

로딩 상태

demo: switch loading

change 이벤트

demo: switch event

비동기 변경

demo: switch async

커스텀 색상

demo: switch color

텍스트 사용

demo: switch text

커스텀 로딩 아이콘

demo: switch icon

API

Props

Attribute 설명 Type 기본값
v-model Switch 상태 boolean | string | number false
disabled v4.3.2 비활성 상태 boolean false
loading 로딩 상태 boolean false
active-color 활성일 때 배경색 string #fa2c19
inactive-color 비활성일 때 배경색 string #ebebeb
active-text 활성일 때 설명 문구 string -
inactive-text 비활성일 때 설명 문구 string -
active-value 활성일 때 값 boolean | string | number true
inactive-value 비활성일 때 값 boolean | string | number false
disable deprecated 비활성 상태 boolean false

Slots

이름 설명
icon loading 아이콘 슬롯

Events

Event 설명 인자
change 체크 상태가 바뀌면 발생해요 (value: boolean,event: Event)

Types v4.3.4

컴포넌트는 다음 타입 정의를 내보내요:

import type {
  SwitchProps,
  SwitchInstance
} from '@nutui/nutui'

테마 (Theming)

CSS Variables

컴포넌트는 스타일을 커스터마이즈할 수 있는 CSS 변수를 제공해요. ConfigProvider 컴포넌트를 참고하세요.

이름 기본값
--nut-switch-close-bg-color #ebebeb
--nut-switch-close-cline-bg-color #f0f0f0
--nut-switch-width 36px
--nut-switch-height 21px
--nut-switch-line-height 21px
--nut-switch-border-radius 21px
--nut-switch-inside-width 13px
--nut-switch-inside-height 13px
--nut-switch-inside-open-transform translateX(146%)
--nut-switch-inside-close-transform translateX(30%)

더 알아보기 (Learn more)