2017-05-18 04:28:45 +00:00
|
|
|
<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-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
|
2017-10-18 10:31:03 +00:00
|
|
|
:::demo Bind `v-model` to a `Boolean` typed variable. The `true-color` and `false-color` attribute decides the background color in two states.
|
2016-11-10 13:46:55 +00:00
|
|
|
|
|
|
|
```html
|
2017-09-13 07:51:01 +00:00
|
|
|
<el-switch v-model="value1">
|
2016-11-10 13:46:55 +00:00
|
|
|
</el-switch>
|
|
|
|
<el-switch
|
|
|
|
v-model="value2"
|
2017-10-18 10:31:03 +00:00
|
|
|
true-color="#13ce66"
|
|
|
|
false-color="#ff4949">
|
2016-11-10 13:46:55 +00:00
|
|
|
</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
|
|
|
:::
|
|
|
|
|
2017-09-13 07:51:01 +00:00
|
|
|
### Text description
|
2017-10-18 10:31:03 +00:00
|
|
|
:::demo You can add `true-text` and `false-text` attribute to show texts.
|
2017-09-13 07:51:01 +00:00
|
|
|
|
|
|
|
```html
|
|
|
|
<el-switch
|
|
|
|
v-model="value3"
|
2017-10-18 10:31:03 +00:00
|
|
|
true-text="Pay by month"
|
|
|
|
false-text="Pay by year">
|
2017-09-13 07:51:01 +00:00
|
|
|
</el-switch>
|
|
|
|
<el-switch
|
|
|
|
style="display: block"
|
|
|
|
v-model="value4"
|
2017-10-18 10:31:03 +00:00
|
|
|
true-color="#13ce66"
|
|
|
|
false-color="#ff4949"
|
|
|
|
true-text="Pay by month"
|
|
|
|
false-text="Pay by year">
|
2017-09-13 07:51:01 +00:00
|
|
|
</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-10-18 10:31:03 +00:00
|
|
|
:::demo You can set `true-value` and `false-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">
|
2017-05-19 17:49:02 +00:00
|
|
|
<el-switch
|
2017-09-13 07:51:01 +00:00
|
|
|
v-model="value5"
|
2017-10-18 10:31:03 +00:00
|
|
|
true-color="#13ce66"
|
|
|
|
false-color="#ff4949"
|
|
|
|
true-value="100"
|
|
|
|
false-value="0">
|
2017-05-19 17:49:02 +00:00
|
|
|
</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
|
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
|
2017-09-13 07:51:01 +00:00
|
|
|
v-model="value6"
|
2016-11-10 13:46:55 +00:00
|
|
|
disabled>
|
|
|
|
</el-switch>
|
|
|
|
<el-switch
|
2017-09-13 07:51:01 +00:00
|
|
|
v-model="value7"
|
2016-11-10 13:46:55 +00:00
|
|
|
disabled>
|
|
|
|
</el-switch>
|
|
|
|
|
2016-11-14 10:10:52 +00:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2017-09-13 07:51:01 +00:00
|
|
|
value6: true,
|
|
|
|
value7: false
|
2016-11-14 10:10:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</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
|
2017-09-13 07:51:01 +00:00
|
|
|
width | width of Switch | number | — | 40
|
2017-10-18 10:31:03 +00:00
|
|
|
true-icon-class | class name of the icon displayed when in `on` state, overrides `true-text` | string | — | —
|
|
|
|
false-icon-class |class name of the icon displayed when in `off` state, overrides `false-text`| string | — | —
|
|
|
|
true-text | text displayed when in `on` state | string | — | —
|
|
|
|
false-text | text displayed when in `off` state | string | — | —
|
|
|
|
true-value | switch value when in `on` state | boolean / string / number | — | true
|
|
|
|
false-value | switch value when in `off` state | boolean / string / number | — | false
|
|
|
|
true-color | background color when in `on` state | string | — | #409EFF
|
|
|
|
false-color | background color when in `off` state | string | — | #C0CCDA
|
2016-11-13 03:58:45 +00:00
|
|
|
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
|
2017-10-16 06:07:24 +00:00
|
|
|
|
|
|
|
### Methods
|
|
|
|
Method | Description | Parameters
|
|
|
|
------|--------|-------
|
|
|
|
focus | focus the Switch component | —
|