Switch 开关
表示两种相互对立的状态间的切换,多用于触发「开/关」。
基础用法
绑定 v-model
到一个 Boolean
类型的变量。
开关的类型 type
共五种类型:主要( primary
)、成功( success
)、信息( info
)、警告( warning
)、危险( danger
)。
自定义颜色
除了通过 type
属性控制颜色外,还可以自由的设置开关的颜色。
可以使用 on-color
属性与 off-color
属性来设置开关的背景色。 使用 handle-on-color
属性与 handle-off-color
属性来设置开关按钮的颜色。 设置的颜色会覆盖 type
属性控制的颜色。
自定义尺寸
设置 width
和 height
属性指定宽和高。
文字描述
使用 on-text
属性与 off-text
属性来设置开关的文字描述。
禁用/只读
开关的禁用状态和只读状态。
设置 disabled
属性和 readonly
属性即可。
扩展的 value 类型
设置 on-value
和 off-value
属性,接受 Boolean
, String
或 Number
类型的值。
绑定值: true
Switch 属性
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
model-value / v-model | 绑定值 | string / number / boolean | — | false |
type | 类型 | string | primary / success / info / warning / danger | primary |
on-color | switch的状态为 on 时的背景色 | string | — | — |
off-color | switch的状态为 off 时的背景色 | string | — | — |
handle-on-color | switch的状态为 on 时开关按钮的颜色 | string | — | — |
handle-off-color | switch的状态为 off 时开关按钮的颜色 | string | — | — |
width | switch的宽度,无需带单位,自动带上单位 px | string / number | — | — |
height | switch的宽度,无需带单位,自动带上单位 px | string / number | — | — |
on-value | switch的状态为 on 时的值 | string / number / boolean | — | true |
off-value | switch的状态为 off 时的值 | string / number / boolean | — | false |
on-text | switch的状态为 on 时的文字描述 | string | — | — |
off-text | switch的状态为 off 时的文字描述 | string | — | — |
disabled | 是否禁用状态 | boolean | — | false |
readonly | 是否只读状态 | boolean | — | false |
Switch 事件
事件名 | 说明 | 回调参数 |
---|---|---|
change | 当绑定值变化时触发的事件 | value |