Switch
Demos
Size variants
Available size variants for the ui
prop: large
/small
.
<template>
<article>
<section>
<veui-switch v-model="readonly">
Read-only
</veui-switch>
<veui-switch v-model="disabled">
Disabled
</veui-switch>
</section>
<section>
<veui-switch
v-model="on"
:readonly="readonly"
:disabled="disabled"
ui="large"
>
Large size
</veui-switch>
<veui-switch
v-model="on"
:readonly="readonly"
:disabled="disabled"
>
Normal size
</veui-switch>
<veui-switch
v-model="on"
:readonly="readonly"
:disabled="disabled"
ui="small"
>
Small size
</veui-switch>
</section>
</article>
</template>
<script>
import { Switch } from 'veui'
export default {
components: {
'veui-switch': Switch
},
data () {
return {
on: false,
readonly: false,
disabled: false
}
}
}
</script>
True/false values
Use the true-value
and false-value
props to customize the model
value (used in its v-model
) of the checkbox in checked/unchecked state.
Status: On
<template>
<article>
<veui-switch
v-model="status"
true-value="ON"
false-value="OFF"
>
Bluetooth
</veui-switch>
<p>Status: {{ statusMap[status] }}</p>
</article>
</template>
<script>
import { Switch } from 'veui'
const STATUS_MAP = {
ON: 'On',
OFF: 'Off'
}
export default {
components: {
'veui-switch': Switch
},
data () {
return {
status: 'ON',
statusMap: STATUS_MAP
}
}
}
</script>
API
Props
Name | Type | Default | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
ui | string | - | Style variants.
| ||||||
model | * | - |
The value of the switch, being | ||||||
checked | boolean | false |
Whether the checkbox is on. | ||||||
true-value | * | true | The value for checked state. | ||||||
false-value | * | false | The value for unchecked state. | ||||||
disabled | boolean | false | Whether the switch is disabled. | ||||||
readonly | boolean | false | Whether the switch is read-only. |
Slots
Name | Description |
---|---|
default | The label text of the switch. The switch is toggled when the label is clicked. Displays nothing by default. |
Events
Name | Description |
---|---|
change | Triggered when user toggles the state of the switch. The callback parameter list is (checked: boolean) . checked denotes whether the switch is on. |
input |
Triggered when the check state is changed. The callback parameter list is |
Additionally, Switch
exposes the following native events:
auxclick
, click
, contextmenu
, dblclick
, mousedown
, mouseenter
, mouseleave
, mousemove
, mouseover
, mouseout
, mouseup
, select
, wheel
, keydown
, keypress
, keyup
, focus
, blur
, focusin
, focusout
.
The callback parameter is the corresponding native event object for all events above.