Skip to content

Switch

基础用法

html

<pa-switch v-model="checked" />
ts

import { ref } from 'vue'

const checked = ref<boolean>(true)

禁用状态

html

<pa-switch v-model="checked" disabled />
ts

import { ref } from 'vue'

const checked = ref<boolean>(true)

加载状态

html

<pa-switch v-model="checked" loading />
ts

import { ref } from 'vue'

const checked = ref<boolean>(true)

自定义大小

html

<pa-switch v-model="checked" size="18px" />
ts

import { ref } from 'vue'

const checked = ref<boolean>(true)

异步控制

html

<pa-switch :model-value="checked" :loading="loading" @change="onChange" />
ts

import { ref } from 'vue'
import type { SwitchValue } from '../..'

const checked = ref<boolean>(true)
const loading = ref<boolean>(false)

const onChange = (value: SwitchValue) => {
  loading.value = true
  setTimeout(() => {
    checked.value = value as boolean
    loading.value = false
  }, 2000)
}

自定义颜色

html

<pa-switch v-model="checked" active-color="#ee0a24" inactive-color="#aaa" />
ts

import { ref } from 'vue'

const checked = ref<boolean>(true)

自定义值

html

<pa-switch v-model="checked" active-value="开" inactive-value="关" />
<text class="ml-40">{{ checked }}</text>
ts

import { ref } from 'vue'

const checked = ref<string>('开')

Switch Props

参数说明类型默认值
modelValue开关状态SwitchValuefalse
activeValue打开时组件的值SwitchValuetrue
inactiveValue关闭组件的值SwitchValuefalse
activeColor打开时的背景颜色CSSProperties['background-color']-
inactiveColor关闭时的背景颜色CSSProperties['background-color']-
loading禁用状态boolean-
disabled加载状态boolean-
size开关尺寸string-

Switch Event

事件名参数
update:modelValue(value: SwitchValue)
change(value: SwitchValue)

Switch Slot

名称说明

样式变量

名称默认值
--pa-switch-size24px