Switch is used for switching between two opposing states.
### Basic usage
:::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.
:::demo Bind `v-model` to a `Boolean` typed variable. The `on-color` and `off-color` attribute decides the background color in two states.
```html
<el-switch
v-model="value1"
on-text=""
off-text="">
<el-switchv-model="value1">
</el-switch>
<el-switch
v-model="value2"
...
...
@@ -52,14 +51,45 @@ Switch is used for switching between two opposing states.
```
:::
### Text description
:::demo You can add `on-text` and `off-text` attribute to show texts.
```html
<el-switch
v-model="value3"
on-text="Pay by month"
off-text="Pay by year">
</el-switch>
<el-switch
style="display: block"
v-model="value4"
on-color="#13ce66"
off-color="#ff4949"
on-text="Pay by month"
off-text="Pay by year">
</el-switch>
<script>
exportdefault{
data(){
return{
value3:true,
value4:true
}
}
};
</script>
```
:::
### Extended value types
:::demo You can set `on-value` and `off-value` attributes. They both receive a `Boolean`, `String` or `Number` typed value.