# tui-switch 开关选择器
介绍
开关选择器,原生组件增强,支持放大缩小。
# 引入
# uni-app引入
第一种,手动引入(可全局引入)
import tuiSwitch from "@/components/thorui/tui-switch/tui-switch.vue"
export default {
components:{
tuiSwitch
}
}
第二种,开启easycom组件模式,如果不了解如何配置,可先查看 官网文档 (opens new window)。
# uni-app版本平台差异说明
App-Nvue | App-vue | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 字节小程序 | QQ小程序 |
---|---|---|---|---|---|---|---|
√ | √ | √ | √ | √ | √ | √ | √ |
# 微信小程序引入(可在app.json中全局引入)
{
"usingComponents": {
"tui-switch": "/components/thorui/tui-switch/tui-switch"
}
}
# 代码演示
部分功能演示,具体可参考示例程序以及文档API。
默认使用
<tui-switch @change="change"></tui-switch>
默认打开
通过 checked
属性设置是否打开。
<tui-switch checked></tui-switch>
禁用状态
通过 disabled
属性设置是否禁用。
<tui-switch disabled></tui-switch>
改变颜色
通过 color
属性设置颜色。
<tui-switch checked color="#07c160"></tui-switch>
改变大小
通过 scaleRatio
属性设置缩放倍数,改变大小。
<!--uni-app-->
<tui-switch :scaleRatio="0.8"></tui-switch>
<!--微信小程序-->
<tui-switch scaleRatio="{{0.8}}"></tui-switch>
# Slots
名称 | 说明 |
---|---|
- | - |
# Props
参数 | 类型 | 说明 | 默认值 |
---|---|---|---|
name | String | 开关选择器名称 | - |
checked | Boolean | 是否选中 | false |
disabled | Boolean | 是否禁用 | false |
type | String | 样式,有效值:switch, checkbox | switch |
color | String | switch选中颜色 | #5677fc |
borderColor | String | 边框颜色,type=checkbox时生效 | #ccc |
checkMarkColor | String | 对号颜色,type=checkbox时生效 | #fff |
scaleRatio | [Number, String] | 缩放倍数,改变大小 | 1 |
# Events
事件名 | 说明 | 回调参数 |
---|---|---|
change | checked 改变时触发 change 事件 | event.detail={ value:checked} |
# 预览
请以移动端效果为准,touch事件目前尚未在PC端做兼容。
# 线上程序扫码预览
![]() | ![]() | ![]() |
---|---|---|
ThorUI组件库小程序码 | H5二维码 | ThorUI示例小程序码 |