Skip to content

Switch 开关

选中值的开关

基础用法

<template>
	<LiSwitch v-model="val"></LiSwitch>
	<LiSwitch v-model="val" type="primary"></LiSwitch>
	<LiSwitch v-model="val" type="success"></LiSwitch>
	<LiSwitch v-model="val" type="danger"></LiSwitch>
	<LiSwitch v-model="val" type="warning"></LiSwitch>
	<LiSwitch v-model="val" type="info"></LiSwitch>
</template>
<script setup lang="ts">
	import { ref } from "vue";

	const val = ref(false);
</script>

禁用状态

使用disabled控制禁用状态

<template>
	<LiSwitch disabled v-model="val"></LiSwitch>
	<LiSwitch disabled v-model="val" type="primary"></LiSwitch>
	<LiSwitch disabled v-model="val" type="success"></LiSwitch>
	<LiSwitch disabled v-model="val" type="danger"></LiSwitch>
	<LiSwitch disabled v-model="val" type="warning"></LiSwitch>
	<LiSwitch disabled v-model="val" type="info"></LiSwitch>
</template>
<script setup lang="ts">
	import { ref } from "vue";

	const val = ref(false);
</script>

自定义值

使用enable-valdisable-val控制禁用状态

<template>
	<LiSwitch v-model="val" enable-val="开" disable-val="关"></LiSwitch>
	<LiSwitch
		v-model="val"
		enable-val="开"
		disable-val="关"
		type="primary"
	></LiSwitch>
	<LiSwitch
		v-model="val"
		enable-val="开"
		disable-val="关"
		type="success"
	></LiSwitch>
	<LiSwitch
		v-model="val"
		enable-val="开"
		disable-val="关"
		type="danger"
	></LiSwitch>
	<LiSwitch
		v-model="val"
		enable-val="开"
		disable-val="关"
		type="warning"
	></LiSwitch>
	<LiSwitch
		v-model="val"
		enable-val="开"
		disable-val="关"
		type="info"
	></LiSwitch>
</template>
<script setup lang="ts">
	import { ref } from "vue";

	const val = ref(false);
</script>

插槽

使用checked获取当前值

false
<template>
	<LiSwitch v-model="val">
		<template #default="{ checked }">
			{{ checked }}
		</template>
	</LiSwitch>
</template>
<script setup lang="ts">
	import { ref } from "vue";

	const val = ref(false);
</script>

Input Attributes

参数说明类型可选值默认值
disabled禁用booleanfalse
disable-val关值string
enable-val开值string
type类型stringdefault / primary / success / warning / info / dangerdefault

Input Slots

插槽名说明
-默认, checked 为当前值

Released under the MIT License.