组件库文档 tmui.design 
开关 Switch 
Switch 开关是用于在两种状态下选择唯一一种状态或值的组件
🌶️ 开关 Switch 示例 
查看模拟效果+
示例模板
vue
<template>
	<tm-app>
		<tm-sheet>
			<tm-text :font-size="24" _class="text-weight-b" label="基础示例,更多见文档"></tm-text>
			<tm-divider></tm-divider>
			<view class="flex flex-row">
				<tm-switch offIcon="tmicon-times" size="mini"></tm-switch>
				<tm-switch size="normal" color="red" :defaultValue="true" :margin="[12, 0]"></tm-switch>
				<tm-switch size="large" color="green" :defaultValue="true" :margin="[12, 0]"></tm-switch>
			</view>
		</tm-sheet>
		<tm-sheet>
			<tm-text :font-size="24" _class="text-weight-b" label="其它样式属性"></tm-text>
			<tm-divider></tm-divider>
			<view class="flex flex-row">
				<tm-switch linear="left" linearDeep="accent" :defaultValue="true" :margin="[12, 0]"></tm-switch>
				<tm-switch unCheckedColor="red" color="red" text :label="['开', '关']"></tm-switch>
				<tm-switch
					:label="['形状', '方形']"
					:width="200"
					:height="58"
					:round="2"
					color="green"
					:defaultValue="true"
					:margin="[12, 0]"
				></tm-switch>
			</view>
		</tm-sheet>
		<tm-sheet>
			<tm-text :font-size="24" _class="text-weight-b" label="加载和禁用"></tm-text>
			<tm-divider></tm-divider>
			<view class="flex flex-row">
				<tm-switch load linear="left" linearDeep="accent" color="red" :defaultValue="true" :margin="[12, 0]"></tm-switch>
				<tm-switch disabled linear="left" linearDeep="accent" color="green" :defaultValue="true" :margin="[12, 0]"></tm-switch>
			</view>
		</tm-sheet>
		<tm-sheet>
			<tm-text :font-size="24" _class="text-weight-b" label="异步开关"></tm-text>
			<tm-divider></tm-divider>
			<view class="flex flex-row">
				<tm-switch :beforeChecked="beforeChecked" linear="left" linearDeep="accent" color="blue" :margin="[12, 0]"></tm-switch>
			</view>
		</tm-sheet>
	</tm-app>
</template>
<script lang="ts" setup>
import { ref, computed } from 'vue'
import { onShow, onLoad } from '@dcloudio/uni-app'
import tmApp from '@/tmui/components/tm-app/tm-app.vue'
import tmSheet from '@/tmui/components/tm-sheet/tm-sheet.vue'
import tmText from '@/tmui/components/tm-text/tm-text.vue'
import tmSwitch from '@/tmui/components/tm-switch/tm-switch.vue'
import tmDivider from '@/tmui/components/tm-divider/tm-divider.vue'
function beforeChecked() {
	return new Promise((res) => {
		setTimeout(function () {
			res(true)
		}, 1000)
	})
}
</script>🌶️ 兼容性 
| APP-VUE | APP-NVUE | 小程序 | WEB/H5 | VUE3/TS | 
|---|---|---|---|---|
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | 
🌱 参数 
本组件含有公共属性 公共属性
| 参数名 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| width | Number | 0 | 组件宽度 | 
| height | Number | 0 | 组件高度 | 
| size | String | normal | 组件大小,可取的值有:mini,normal,large | 
| margin | Array | [0,0] | 组件外边距 | 
| transprent | Boolean | false | 组件是否透明 | 
| modelValue / v-model | Boolean | false | 组件的值,可双向绑定 | 
| defaultValue | Boolean | false | 组件默认值 | 
| selectedv3.0.83+ | Boolean,String,Number | true | 打开时的值 | 
| unSelectedv3.0.83+ | Boolean,String,Number | false | 关闭时的值 | 
| color | String | primary | 组件激活后的颜色,即按钮开启状态的颜色 | 
| unCheckedColor | String | 组件未激活的颜色,即按钮关闭状态的颜色 | |
| barColor | String | white | 开关上小圆球的背景色 | 
| round | Number | 10 | 组件的圆角值 | 
| load | Boolean | false | 是否显示组件加载状态,加载状态下组件圆形内按钮会变成旋转的加载图标 | 
| beforeChecked | Function / String / Number | false | 开关状态改变前执行的函数 | 
| barIcon | String | tmicon-check | 开启时,开关按钮上圆形内的图标 | 
| offIcon | String | - | 关闭时,开关按钮上圆形内的图标 | 
| disabled | Boolean | false | 是否禁用组件 | 
| label | Array | ["",""] | 开关开启关闭时内部的文字,如:["开启","关闭"] | 
🌹 事件 
| 事件名 | 参数 | 返回数据 | 描述 | 
|---|---|---|---|
| change | / | modelValue | 开关状态改变时返回当前的状态 | 
| click | / | / | 开关被点击后的函数 | 
🌽 slot插槽 
无
🥗 ref方法 
无
