Switch
组件类型:UxSwitchComponentPublicInstance
扩展官方组件
平台兼容性
UniApp X
| Android | iOS | web | 鸿蒙 Next | 小程序 |
|---|---|---|---|---|
| √ | √ | √ | √ | √ |
UniApp Vue Nvue
| Android | iOS | web | 鸿蒙 Next | 小程序 |
|---|---|---|---|---|
| x | x | √ | x | x |
Props
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | String | 表单的控件名称,作为键值对的一部分与表单(form组件)一同提交 | |
| theme | String | 主题颜色 | |
| checked | Boolean | false | 是否选中 |
| size | String | normal | 尺寸 |
| color | String | $ux.Conf.primaryColor | 颜色 |
| darkColor | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
| margin | Array | 边距[上右下左][上下左右][上下左右] | |
| mt | Any | 距上单位px | |
| mr | Any | 距右单位px | |
| mb | Any | 距下单位px | |
| ml | Any | 距左单位px | |
| padding | Array | 填充[上右下左][上下左右][上下左右] | |
| pt | Any | 上内边距单位px | |
| pr | Any | 右内边距单位px | |
| pb | Any | 下内边距单位px | |
| pl | Any | 左内边距单位px | |
| xstyle | Array | 自定义样式 | |
| disabled | Boolean | false | 是否禁用 |
theme
| 值 | 说明 |
|---|---|
| primary | 主色 |
| warning | 警告 |
| success | 成功 |
| error | 错误 |
| info | 文本 |
size
| 值 | 说明 |
|---|---|
| normal正常 | |
| small小尺寸 | |
| large大尺寸 |
darkColor
| 值 | 说明 |
|---|---|
| none不显示 | |
| auto自动适配深色模式 | |
| color其他颜色 | |
Events
| 事件名 | 说明 | 参数 |
|---|---|---|
| change | 值改变时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="开关选择器" :bold="true">
<ux-text text="基于官方Switch扩展组件"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="主题" :bold="true">
<ux-text text="多种主题可配置,适配暗黑模式" :mb="15"></ux-text>
<ux-row>
<ux-switch theme="primary" :checked="checked" @change="change"></ux-switch>
<ux-switch theme="warning" :checked="checked" @change="change"></ux-switch>
<ux-switch theme="success" :checked="checked" @change="change"></ux-switch>
<ux-switch theme="error" :checked="checked" @change="change"></ux-switch>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="尺寸" :bold="true">
<ux-text text="支持大中小尺寸" :mb="15"></ux-text>
<ux-row>
<ux-switch size="small" :checked="checked" @change="change"></ux-switch>
<ux-switch :checked="checked" @change="change"></ux-switch>
<ux-switch size="large" :checked="checked" @change="change"></ux-switch>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="禁用" :bold="true">
<ux-text text="禁用组件" :mb="15"></ux-text>
<ux-row>
<ux-switch :disabled="true" :checked="checked" @change="change"></ux-switch>
</ux-row>
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template><template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="开关选择器" :bold="true">
<ux-text text="基于官方Switch扩展组件"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="主题" :bold="true">
<ux-text text="多种主题可配置,适配暗黑模式" :mb="15"></ux-text>
<ux-row>
<ux-switch theme="primary" :checked="checked" @change="change"></ux-switch>
<ux-switch theme="warning" :checked="checked" @change="change"></ux-switch>
<ux-switch theme="success" :checked="checked" @change="change"></ux-switch>
<ux-switch theme="error" :checked="checked" @change="change"></ux-switch>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="尺寸" :bold="true">
<ux-text text="支持大中小尺寸" :mb="15"></ux-text>
<ux-row>
<ux-switch size="small" :checked="checked" @change="change"></ux-switch>
<ux-switch :checked="checked" @change="change"></ux-switch>
<ux-switch size="large" :checked="checked" @change="change"></ux-switch>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="禁用" :bold="true">
<ux-text text="禁用组件" :mb="15"></ux-text>
<ux-row>
<ux-switch :disabled="true" :checked="checked" @change="change"></ux-switch>
</ux-row>
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
import { UxSwitchEvent } from '@/uni_modules/ux-frame'
const title = ref('')
const checked = ref(false)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/switch.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function change(e: UxSwitchEvent) {
checked.value = e.value
}
</script><script setup>
import * as plus from '@/uni_modules/ux-plus'
import { UxSwitchEvent } from '@/uni_modules/ux-frame'
const title = ref('')
const checked = ref(false)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/switch.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function change(e: UxSwitchEvent) {
checked.value = e.value
}
</script>css
<style lang="scss">
</style><style lang="scss">
</style>