Radio
组件类型:UxRadioComponentPublicInstance
平台兼容性
UniApp X
| Android | iOS | web | 鸿蒙 Next | 小程序 |
|---|---|---|---|---|
| √ | √ | √ | √ | √ |
UniApp Vue Nvue
| Android | iOS | web | 鸿蒙 Next | 小程序 |
|---|---|---|---|---|
| x | x | √ | x | x |
Props
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | String | 标识符,在回调事件中返回 | |
| theme | String | 主题颜色 | |
| checked | Boolean | 选择状态优先级最高 | |
| value | String | 值 | |
| mode | String | radio | 单选模式 |
| shape | String | radio | 形状,mode=cell时无效 |
| radius | Any | 17 | 直径 |
| text | String | 文案 | |
| size | Any | $ux.Conf.fontSize | 字体大小 |
| color | String | $ux.Conf.fontColor | 文本颜色 |
| darkColor | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
| checkedColor | String | #ffffff | 选择颜色 |
| checkedColorDark | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
| backgroundColor | String | $ux.Conf.backgroundColor | radio背景色 |
| backgroundDark | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
| activeBackgroundColor | String | $ux.Conf.primaryColor | radio背景选择颜色 |
| activeBackgroundDark | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
| border | Boolean | true | 显示cell下划线 |
| borderColor | String | $ux.Conf.borderColor | radio边框色 |
| activeBorderColor | String | $ux.Conf.primaryColor | radio边框选择颜色 |
| titleStyle | String | cell标题样式 | |
| cellPadding | String | cellpadding | |
| readonly | Boolean | false | 只读 |
| disabled | Boolean | false | 是否禁用 |
| 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 | 自定义样式 |
theme
| 值 | 说明 |
|---|---|
| primary | 主色 |
| warning | 警告 |
| success | 成功 |
| error | 错误 |
| info | 文本 |
mode
| 值 | 说明 |
|---|---|
| radio单选 | |
| button按钮 | |
| cell单元格 | |
shape
| 值 | 说明 |
|---|---|
| circle圆形 | |
| square方形 | |
darkColor
| 值 | 说明 |
|---|---|
| none不显示 | |
| auto自动适配深色模式 | |
| color其他颜色 | |
checkedColorDark
| 值 | 说明 |
|---|---|
| none不显示 | |
| auto自动适配深色模式 | |
| color其他颜色 | |
backgroundDark
| 值 | 说明 |
|---|---|
| none不显示 | |
| auto自动适配深色模式 | |
| color其他颜色 | |
activeBackgroundDark
| 值 | 说明 |
|---|---|
| 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="支持单选、单选组,支持单选框、按钮、单元格3种显示模式"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单选" :bold="true">
<ux-text text="单选模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-row>
<ux-radio value="1" text="uniapp-x" theme="primary" :mr="10"></ux-radio>
<ux-radio value="2" text="flutter" theme="success" :mr="10"></ux-radio>
<ux-radio value="3" text="禁用" theme="error" :disabled="true"></ux-radio>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单选组" :bold="true">
<ux-text text="单选组模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-col>
<ux-radio-group v-model="value" :inverse="false">
<ux-radio value="1" text="uniapp-x" color="red" :mr="10"></ux-radio>
<ux-radio value="2" text="flutter" color="blue" checked-color="red" :mr="10"></ux-radio>
<ux-radio value="3" text="禁用" color="green" :disabled="true"></ux-radio>
</ux-radio-group>
</ux-col>
</ux-card>
<ux-card direction="column" icon="arrowright" title="按钮" :bold="true">
<ux-text text="按钮模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-row>
<ux-radio-group style="flex: 1;" v-model="value" mode="button" direction="col">
<ux-radio value="1" text="按钮1" shape="square" theme="primary"></ux-radio>
<ux-radio value="2" text="按钮2" theme="success" :mt="5"></ux-radio>
<ux-radio value="3" text="禁用" :disabled="true" :mt="5"></ux-radio>
</ux-radio-group>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单元格" :bold="true">
<ux-text text="单元格模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-col>
<ux-radio-group v-model="value" mode="cell" active-background-color="black" active-border-color="black" direction="col">
<ux-radio value="1" text="单元格1" color="red"></ux-radio>
<ux-radio value="2" text="单元格2" shape="square"></ux-radio>
<ux-radio value="3" text="禁用" :disabled="true"></ux-radio>
</ux-radio-group>
</ux-col>
</ux-card>
<ux-card direction="column" icon="arrowright" title="插槽" :bold="true">
<ux-text text="支持插槽自定义内容" :mb="15"></ux-text>
<ux-row>
<ux-radio-group v-model="value" shape="square" theme="error" direction="col">
<ux-radio value="1">
<view style="width: 100%;">
<ux-text :ml="5" text="我是我我是插我是插槽我是插槽槽我是我是插槽插槽我是插我是插槽槽我是插槽是插槽插"></ux-text>
</view>
</ux-radio>
<ux-radio :mt="10" value="2">
<ux-text :ml="5" text="我是插槽2"></ux-text>
</ux-radio>
</ux-radio-group>
</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="支持单选、单选组,支持单选框、按钮、单元格3种显示模式"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单选" :bold="true">
<ux-text text="单选模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-row>
<ux-radio value="1" text="uniapp-x" theme="primary" :mr="10"></ux-radio>
<ux-radio value="2" text="flutter" theme="success" :mr="10"></ux-radio>
<ux-radio value="3" text="禁用" theme="error" :disabled="true"></ux-radio>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单选组" :bold="true">
<ux-text text="单选组模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-col>
<ux-radio-group v-model="value" :inverse="false">
<ux-radio value="1" text="uniapp-x" color="red" :mr="10"></ux-radio>
<ux-radio value="2" text="flutter" color="blue" checked-color="red" :mr="10"></ux-radio>
<ux-radio value="3" text="禁用" color="green" :disabled="true"></ux-radio>
</ux-radio-group>
</ux-col>
</ux-card>
<ux-card direction="column" icon="arrowright" title="按钮" :bold="true">
<ux-text text="按钮模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-row>
<ux-radio-group style="flex: 1;" v-model="value" mode="button" direction="col">
<ux-radio value="1" text="按钮1" shape="square" theme="primary"></ux-radio>
<ux-radio value="2" text="按钮2" theme="success" :mt="5"></ux-radio>
<ux-radio value="3" text="禁用" :disabled="true" :mt="5"></ux-radio>
</ux-radio-group>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单元格" :bold="true">
<ux-text text="单元格模式,可自定义样式和禁用组件" :mb="15"></ux-text>
<ux-col>
<ux-radio-group v-model="value" mode="cell" active-background-color="black" active-border-color="black" direction="col">
<ux-radio value="1" text="单元格1" color="red"></ux-radio>
<ux-radio value="2" text="单元格2" shape="square"></ux-radio>
<ux-radio value="3" text="禁用" :disabled="true"></ux-radio>
</ux-radio-group>
</ux-col>
</ux-card>
<ux-card direction="column" icon="arrowright" title="插槽" :bold="true">
<ux-text text="支持插槽自定义内容" :mb="15"></ux-text>
<ux-row>
<ux-radio-group v-model="value" shape="square" theme="error" direction="col">
<ux-radio value="1">
<view style="width: 100%;">
<ux-text :ml="5" text="我是我我是插我是插槽我是插槽槽我是我是插槽插槽我是插我是插槽槽我是插槽是插槽插"></ux-text>
</view>
</ux-radio>
<ux-radio :mt="10" value="2">
<ux-text :ml="5" text="我是插槽2"></ux-text>
</ux-radio>
</ux-radio-group>
</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'
const title = ref('')
const value = ref('')
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/radio.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
</script><script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const value = ref('')
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/radio.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
</script>css
<style lang="scss">
</style><style lang="scss">
</style>