Skip to content

Radio 单选框

在一组备选项中进行单选。

基础用法

由于选项默认可见,不宜过多,若选项过多,建议使用 Select 选择器。

选中值: 1
vue
<template>
  <x-radio v-model="value" value="1">选项A</x-radio>
  <x-radio v-model="value" value="2">选项B</x-radio>
</template>

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

禁用状态

单选框不可用状态。

vue
<template>
  <x-radio v-model="value" value="1" disabled>禁用选项</x-radio>
  <x-radio v-model="value" value="2" disabled>禁用选项</x-radio>
</template>

单选框组

适用于在多个互斥的选项中选中一个的场景。

选中值: 1
vue
<template>
  <x-radio-group v-model="value">
    <x-radio value="1">选项A</x-radio>
    <x-radio value="2">选项B</x-radio>
    <x-radio value="3">选项C</x-radio>
  </x-radio-group>
</template>

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

按钮样式

按钮样式的单选组合。

vue
<template>
  <x-radio-group v-model="value">
    <x-radio-button value="1">选项A</x-radio-button>
    <x-radio-button value="2">选项B</x-radio-button>
    <x-radio-button value="3">选项C</x-radio-button>
  </x-radio-group>
</template>

按钮样式 - 禁用状态

vue
<template>
  <x-radio-group v-model="value">
    <x-radio-button value="1">选项A</x-radio-button>
    <x-radio-button value="2" disabled>选项B</x-radio-button>
    <x-radio-button value="3">选项C</x-radio-button>
  </x-radio-group>
</template>

整体禁用

vue
<template>
  <x-radio-group v-model="value" disabled>
    <x-radio-button value="1">选项A</x-radio-button>
    <x-radio-button value="2">选项B</x-radio-button>
    <x-radio-button value="3">选项C</x-radio-button>
  </x-radio-group>
</template>

API

Radio Props

属性说明类型默认值
modelValue绑定值string | number | boolean
value单选框的值string | number | boolean
label单选框的标签文本(也可使用默认插槽)string | number
disabled是否禁用booleanfalse
name原生 name 属性string

Radio Events

事件名说明回调参数
update:modelValue绑定值变化时触发(value: string | number | boolean)
change绑定值变化时触发(value: string | number | boolean)

RadioGroup Props

属性说明类型默认值
modelValue绑定值string | number | boolean
disabled是否禁用所有子选项booleanfalse
name原生 name 属性string

RadioGroup Events

事件名说明回调参数
update:modelValue绑定值变化时触发(value: string | number | boolean)
change绑定值变化时触发(value: string | number | boolean)

RadioButton Props

属性说明类型默认值
value单选框的值string | number | boolean
label单选框的标签文本(也可使用默认插槽)string | number
disabled是否禁用booleanfalse
name原生 name 属性string

基于 MIT 许可发布