Radio 单选按钮

介绍

用于在一组备选项中进行单选

安装

  1. import { createApp } from 'vue';
  2. import { Radio } from '@nutui/nutui';
  3. const app = createApp();
  4. app.use(Radio);

基本用法

通过 v-model 绑定值当前选项的 label 。并且必须 nut-radiogroupnut-radio 相结合进行使用

  1. <nut-radiogroup v-model="radioVal">
  2. <nut-radio :label="1">单选框1</nut-radio>
  3. <nut-radio :label="2">单选框2</nut-radio>
  4. </nut-radiogroup>
  1. setup() {
  2. return {
  3. radioVal:"1",
  4. };
  5. }

禁用选择

  1. <nut-radiogroup v-model="radioVal3">
  2. <nut-radio :label="1" disabled>禁用单选框</nut-radio>
  3. <nut-radio :label="2" disabled>禁用单选框</nut-radio>
  4. </nut-radiogroup>
  1. setup() {
  2. return {
  3. radioVal3:"1",
  4. };
  5. }

自定义尺寸

  1. <nut-radiogroup v-model="radioVal4">
  2. <nut-radio :label="1" icon-size="12">自定义尺寸12</nut-radio>
  3. <nut-radio :label="2" icon-size="12">自定义尺寸12</nut-radio>
  4. </nut-radiogroup>
  1. setup() {
  2. return {
  3. radioVal4:"1",
  4. };
  5. }

自定义图标

建议 icon-name icon-active-name 一起修改

  1. <nut-radiogroup v-model="radioVal5">
  2. <nut-radio :label="1" icon-name="checklist" icon-active-name="checklist">自定义图标</nut-radio>
  3. <nut-radio :label="2" icon-name="checklist" icon-active-name="checklist">自定义图标</nut-radio>
  4. </nut-radiogroup>
  1. setup() {
  2. return {
  3. radioVal5:"1",
  4. };
  5. }

触发 change 事件

  1. <nut-radiogroup v-model="radioVal6" @change="handleChange3">
  2. <nut-radio :label="1" >触发事件</nut-radio>
  3. <nut-radio :label="2" >触发事件</nut-radio>
  4. </nut-radiogroup>
  1. setup() {
  2. const handleChange3 = (value: any) => {
  3. Toast.text(`您选中了${value}`);
  4. }
  5. return {
  6. radioVal6:"1",
  7. handleChange3
  8. };
  9. }

Prop

Radio

字段说明类型默认值
disabled是否禁用选择Booleanfalse
icon-size图标尺寸String、Number18
icon-name图标名称,选中前(建议和icon-active-name一起修改)String‘check-normal’
icon-active-name图标名称,选中后(建议和icon-name一起修改)String‘check-checked’
label单选框标识String、Number、Boolean-

RadioGroup

字段说明类型默认值
v-model当前选中项的标识符,与label值一致时呈选中状态String、Number、Boolean-
text-position文本所在的位置,可选值:left,rightStringright

RadioGroup Event

字段说明回调参数
change值变化时触发当前选中项值(label)【设置label后有值、默认为空】

Radio  单选按钮 - 图1