Skip to content

Radio 单选框

介绍

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

基础用法

通过 v-model 绑定选中的值,可设置 name 自定义选项值。

html
<vd-radio-group v-model="checked">
  <vd-radio name="1">单选框 1</vd-radio>
  <vd-radio name="2">单选框 2</vd-radio>
</vd-radio-group>
ts
const checked = ref('1');

预设形状

通过 shape 设置单选框的形状。

html
<vd-radio-group v-model="checked">
  <vd-radio label="圆形单选" name="1" />
  <vd-radio label="方形单选" name="2" shape="square" />
  <vd-radio label="球形单选" name="3" shape="circle" />
</vd-radio-group>
ts
const checked = ref('1');

纵向排列

通过 vertical 设置单选框纵向排列。

html
<vd-radio-group v-model="checked" vertical>
  <vd-radio label="单选框 1" name="1" />
  <vd-radio label="单选框 2" name="2" />
</vd-radio-group>
ts
const checked = ref('1');

禁用状态

通过 disabled 设置单选框禁用状态。

html
<vd-radio-group v-model="checked">
  <vd-radio label="单选框 1" name="1" />
  <vd-radio label="单选框 2" name="2" disabled />
</vd-radio-group>
ts
const checked = ref('1');

卡片主题

通过 theme 设置单选框主题样式。

html
<vd-radio-group v-model="checked" theme="card">
  <vd-radio label="单选框 1" name="1" />
  <vd-radio label="单选框 2" name="2" />
</vd-radio-group>
ts
const checked = ref('1');

标签位置

通过 label-position 设置单选框标签的位置。

html
<vd-radio-group
  v-model="checked"
  theme="card"
  label-position="left"
>
  <vd-radio label="单选框 1" name="1" />
  <vd-radio label="单选框 2" name="2" />
</vd-radio-group>
ts
const checked = ref('1');

自定义图标

通过 icon 设置单选框的图标。

html
<vd-radio-group v-model="checked" theme="card">
  <vd-radio label="单选框1" name="1" icon="star-fill" />
  <vd-radio label="单选框2" name="2" icon="love-fill" />
</vd-radio-group>
ts
const checked = ref('1');

搭配弹出层使用

可搭配 Popover 组件使用,实现弹出层选择组。

html
<vd-popup
  v-model="picker.show"
  position="bottom"
  title="搭配弹出层使用"
  round
  closeable
>
  <vd-radio-group v-model="picker.value" theme="card" label-position="left">
    <vd-radio v-for="num in 8" :key="num" :label="`单选框${num}`" :name="num" />
  </vd-radio-group>
</vd-popup>
ts
const picker = reactive({
  show: false,
  value: '1',
});

API

RadioGroup Props

参数说明类型默认值
v-model选中项标识名称string | number-
theme主题default carddefault
shape形状round square circleround
icon图标IconsName-
label-position标签位置left rightright
label-disabled标签是否禁用booleanfalse
vertical是否纵向排列booleanfalse
disabled是否禁用booleanfalse

Radio Props

参数说明类型默认值
name标识名称string | number-
shape形状round square circleround
icon图标IconsName-
label标签string-
label-position标签位置left rightright
label-disabled标签是否禁用booleanfalse
disabled是否禁用booleanfalse

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

RadioGroup Events

事件名说明回调参数
click点击时触发MouseEvent
change选中改变时触发string | number
updated状态改变时触发RadioGroupCheckedData

Radio Events

事件名说明回调参数
click点击时触发MouseEvent
change选中改变时触发boolean

RadioGroup Slots

名称说明
default自定义内容

Radio Slots

名称说明
icon图标
label标签

赣ICP备2025061025号-1