2016-11-13 03:58:45 +00:00
< script >
export default {
data() {
return {
value1: true,
value2: true,
value3: true
}
}
};
< / script >
2016-11-10 13:46:55 +00:00
2016-11-13 03:58:45 +00:00
## Switch
2016-11-10 13:46:55 +00:00
2016-12-08 07:23:21 +00:00
Switch is used for switching between two opposing states.
2016-11-10 13:46:55 +00:00
2016-11-13 03:58:45 +00:00
### Basic usage
2016-11-10 13:46:55 +00:00
2016-11-13 03:58:45 +00:00
:::demo Bind `v-model` to a `Boolean` typed variable. You can add `on-text` or `off-text` attribute to show texts when the component is `on` or `off` , respectively. The `on-color` and `off-color` attribute decides the background color in two states.
2016-11-10 13:46:55 +00:00
```html
< el-switch
v-model="value1"
on-text=""
off-text="">
< / el-switch >
< el-switch
v-model="value2"
on-color="#13ce66"
off-color="#ff4949">
< / el-switch >
2016-11-14 10:10:52 +00:00
< script >
export default {
data() {
return {
value1: true,
value2: true
}
}
};
< / script >
```
2016-11-10 13:46:55 +00:00
:::
2016-11-13 03:58:45 +00:00
### Disabled
2016-11-10 13:46:55 +00:00
2016-12-08 07:23:21 +00:00
:::demo Adding the `disabled` attribute disables Switch.
2016-11-10 13:46:55 +00:00
```html
< el-switch
v-model="value3"
on-text=""
off-text=""
disabled>
< / el-switch >
< el-switch
v-model="value3"
disabled>
< / el-switch >
2016-11-14 10:10:52 +00:00
< script >
export default {
data() {
return {
value3: true
}
}
};
< / script >
```
2016-11-10 13:46:55 +00:00
:::
### Attributes
2016-11-13 03:58:45 +00:00
Attribute | Description | Type | Accepted Values | Default
2016-11-10 13:46:55 +00:00
----| ----| ----| ----|----
2016-11-13 03:58:45 +00:00
disabled | whether Switch is disabled | boolean | — | false
width | width of Switch | number | — | 58 (with text) / 46 (no text)
on-close-icon | class name of the icon displayed when in `on` state, overrides `on-text` | string | — | —
off-close-icon |class name of the icon displayed when in `off` state, overrides `off-text` | string | — | —
on-text | text displayed when in `on` state | string | — | ON
off-text | text displayed when in `off` state | string | — | OFF
on-color | background color when in `on` state | string | — | #20A0FF
off-color | background color when in `off` state | string | — | #C0CCDA
name| input name of Switch | string | — | —
2016-11-10 13:46:55 +00:00
### Events
2016-11-13 03:58:45 +00:00
Event Name | Description | Parameters
2016-11-10 13:46:55 +00:00
---- | ----| ----
2016-11-13 03:58:45 +00:00
change | triggers when value changes | value after changing