Skip to content

Radio 单选框

用于在互斥的多个备选项中进行单项选择的表单控件,通常结合 <mu-radio-group> 使用。


代码示例

1. 水平排列单选 (Horizontal)

设置 direction="horizontal" 让多个单选框水平同行排列。

vue
<template>
  <mu-radio-group v-model="payMethod" direction="horizontal">
    <mu-radio name="wechat" label="微信支付 WeChat" />
    <mu-radio name="alipay" label="支付宝 Alipay" />
    <mu-radio name="card" label="银行卡 Card" />
  </mu-radio-group>
</template>

<script setup>
import { ref } from 'vue'
const payMethod = ref('wechat')
</script>

2. 垂直列表单选 (Vertical)

默认 direction="vertical" 适用于纵向列表单选。

vue
<template>
  <mu-radio-group v-model="gender" direction="vertical">
    <mu-radio name="male" label="男士 Male" />
    <mu-radio name="female" label="女士 Female" />
    <mu-radio name="secret" label="保密 Secret" />
  </mu-radio-group>
</template>

3. 禁用状态 (Disabled)

设置 disabled 禁止选中特定备选项。

vue
<template>
  <mu-radio-group v-model="option" direction="horizontal">
    <mu-radio name="opt1" label="可用选项 A" />
    <mu-radio name="opt2" disabled label="禁用选项 B" />
  </mu-radio-group>
</template>

API 属性说明

Radio Props

参数名说明类型可选值默认值
name在 RadioGroup 内绑定的选中值标识String | Number | Boolean-''
label单选框右侧显示的文案String-''
disabled是否禁用点击Booleantrue | falsefalse

RadioGroup Props

参数名说明类型可选值默认值
v-model当前选中的 name 标识值String | Number-''
direction子单选框排列方向Stringhorizontal | vertical'vertical'

事件说明 (Events)

事件名说明回调参数
change选中项发生改变时触发(value: String | Number)
update:modelValue双向绑定改变(value: String | Number)

插槽说明 (Slots)

插槽名说明
default自定义单选框右侧 label 文案与内容区域

基于 MIT 协议开源发行

H5 模拟器 (radio)☀️🔄