element/examples/docs/en-US/switch.md

161 lines
3.2 KiB
Markdown
Raw Normal View History

<style>
.demo-box.demo-switch {
.el-switch {
margin: 20px 20px 20px 0;
}
}
</style>
2016-11-13 03:58:45 +00:00
<script>
export default {
data() {
return {
value1: true,
value2: true,
2017-09-13 07:51:01 +00:00
value3: true,
value4: true,
value5: '100',
value6: true,
value7: false
2016-11-13 03:58:45 +00:00
}
}
};
</script>
2016-11-13 03:58:45 +00:00
## Switch
Switch is used for switching between two opposing states.
2016-11-13 03:58:45 +00:00
### Basic usage
2017-09-13 07:51:01 +00:00
:::demo Bind `v-model` to a `Boolean` typed variable. The `on-color` and `off-color` attribute decides the background color in two states.
```html
2017-09-13 07:51:01 +00:00
<el-switch v-model="value1">
</el-switch>
<el-switch
v-model="value2"
on-color="#13ce66"
off-color="#ff4949">
</el-switch>
<script>
export default {
data() {
return {
value1: true,
value2: true
}
}
};
</script>
```
:::
2017-09-13 07:51:01 +00:00
### 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>
export default {
data() {
return {
value3: true,
value4: true
}
}
};
</script>
```
:::
2017-04-28 06:03:42 +00:00
### Extended value types
2017-04-23 06:28:29 +00:00
2017-04-28 06:03:42 +00:00
:::demo You can set `on-value` and `off-value` attributes. They both receive a `Boolean`, `String` or `Number` typed value.
2017-04-23 06:28:29 +00:00
```html
2017-09-13 07:51:01 +00:00
<el-tooltip :content="'Switch value: ' + value5" placement="top">
<el-switch
2017-09-13 07:51:01 +00:00
v-model="value5"
on-color="#13ce66"
off-color="#ff4949"
on-value="100"
off-value="0">
</el-switch>
</el-tooltip>
2017-04-23 06:28:29 +00:00
<script>
export default {
data() {
return {
2017-09-13 07:51:01 +00:00
value5: '100'
2017-04-23 06:28:29 +00:00
}
}
};
</script>
```
:::
2016-11-13 03:58:45 +00:00
### Disabled
:::demo Adding the `disabled` attribute disables Switch.
```html
<el-switch
2017-09-13 07:51:01 +00:00
v-model="value6"
disabled>
</el-switch>
<el-switch
2017-09-13 07:51:01 +00:00
v-model="value7"
disabled>
</el-switch>
<script>
export default {
data() {
return {
2017-09-13 07:51:01 +00:00
value6: true,
value7: false
}
}
};
</script>
```
:::
### Attributes
2016-11-13 03:58:45 +00:00
Attribute | Description | Type | Accepted Values | Default
----| ----| ----| ----|----
2016-11-13 03:58:45 +00:00
disabled | whether Switch is disabled | boolean | — | false
2017-09-13 07:51:01 +00:00
width | width of Switch | number | — | 40
2016-11-13 03:58:45 +00:00
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 | — | —
2017-09-13 07:51:01 +00:00
on-text | text displayed when in `on` state | string | — | —
off-text | text displayed when in `off` state | string | — | —
2017-04-28 06:03:42 +00:00
on-value | switch value when in `on` state | boolean / string / number | — | true
off-value | switch value when in `off` state | boolean / string / number | — | false
on-color | background color when in `on` state | string | — | #409EFF
2016-11-13 03:58:45 +00:00
off-color | background color when in `off` state | string | — | #C0CCDA
name| input name of Switch | string | — | —
### Events
2016-11-13 03:58:45 +00:00
Event Name | Description | Parameters
---- | ----| ----
2016-11-13 03:58:45 +00:00
change | triggers when value changes | value after changing