Switch 开关
基本使用
基本使用
<template>
<div class="margin--every">
<h-switch
v-model="active1"
></h-switch>
<h-switch
width="50px"
v-model="active2"
></h-switch>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const active1 = ref(true)
const active2 = ref(true)
</script>
<style scoped lang="scss">
.margin--every * {
margin: 5px 5px;
}
</style>
加入字体选项
关闭开启
加入字体选项
<template>
<div class="margin--every">
<h-switch
v-model="active"
active-text="开启"
inactive-text="关闭"
></h-switch>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const active = ref(true)
</script>
<style scoped lang="scss">
.margin--every * {
margin: 5px 5px;
}
</style>
改变激活颜色
关闭开启
未选中背景色#ff4949选中背景色#ff4949
改变激活颜色
<template>
<div class="margin--every">
<h-switch
active-text-color="#ff4949"
v-model="active1"
active-text="开启"
inactive-text="关闭"
></h-switch>
<h-switch
v-model="active2"
active-color="#13ce66"
inactive-color="#ff4949"
active-text="选中背景色#ff4949"
inactive-text="未选中背景色#ff4949"
></h-switch>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const active1 = ref(true)
const active2 = ref(true)
</script>
<style scoped lang="scss">
.margin--every * {
margin: 5px 5px;
}
</style>
组件 API
Attributes 属性
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| value | switch 的状态 | boolean | - | - |
| active-text | switch 被选中时的文字 | string | - | - |
| inactive-text | switch 未被选中时的文字 | string | - | - |
| width | switch 的宽度 | string | - | 40px |
| active-color | switch 被选中的背景色 | string | - | #00008B |
| inactive-color | switch 未被选中时的背景色 | string | - | #4169E1 |
| name | switch 对应的 name 属性 | string | - | - |
| activeTextColor | active-text 的颜色 | string | - | #228B22 |
hare-ui