<script>
  export default {
    data() {
      return {
        value1: true,
        value2: true
      }
    }
  };
</script>

# Switch 开关
## 概述

在两种状态间切换时用到的开关选择器。

### 基本使用

:::demo 绑定v-model到一个Boolean类型的变量。可以使用on-text属性与off-text属性来设置开关的文字描述，使用on-color属性与off-color属性来设置开关的背景色。

```
<ut-switch
  v-model="value1"
  on-text=""
  off-text="">
</ut-switch>
<ut-switch
  v-model="value2"
  on-color="#13ce66"
  off-color="#ff4949">
</ut-switch>

<script>
  export default {
    data() {
      return {
        value1: true,
        value2: true
      }
    }
  };
</script>
```
:::


### 禁用状态

:::demo 设置disabled属性，接受一个Boolean，设置true即可禁用。

```
<ut-switch
  v-model="value1"
  disabled
  on-text=""
  off-text="">
</ut-switch>
<ut-switch
  v-model="value2"
  disabled
  on-color="#13ce66"
  off-color="#ff4949">
</ut-switch>

<script>
  export default {
    data() {
      return {
        value1: true,
        value2: true
      }
    }
  };
</script>
```
:::


### API

|参数         |说明           | 类型|默认值|
|---------- |-------- |---------- |-------------  |
| disabled    | 是否可用 | string  |  -          |
| width |switch 的宽度（像素）| number  |  58（有文字）/ 46（无文字） |
|on-icon-class|switch 打开时所显示图标的类名，设置此项会忽略 on-text   | string  |  -          |
|off-icon-class|switch 关闭时所显示图标的类名，设置此项会忽略 off-text | string  |-        |
|on-text|switch 打开时的文字|string|ON|
|off-text|switch 关闭时的文字|	string	|	OFF|
|on-color|switch 打开时的背景色|	string	|	#20A0FF|
|off-color|关闭时的背景色	|string|#C0CCDA|
|name|	switch |对应的 name 属性	|string|	—|	—