Skip to content

Radio

radio

Rule

Basic Example

js
const rule = {
    type: 'radio',
    title: 'Radio Button',
    field: 'radio',
    value: '1',
    props: {
        options: [
            {
                text: 'Radio 1',
                value: '1',
            },
            {
                text: 'Radio 2',
                value: '2',
            },
        ]
    }
}

Props Configuration Examples

Horizontal Layout

js
const rule = {
    type: 'radio',
    title: 'Delivery Method',
    field: 'delivery',
    value: '1',
    props: {
        options: [
            { text: 'Express Delivery', value: '1' },
            { text: 'Store Pickup', value: '2' },
            { text: 'Same City Delivery', value: '3' },
        ],
        direction: 'horizontal',
    }
}

Custom Style

js
const rule = {
    type: 'radio',
    title: 'Product Status',
    field: 'status',
    value: '1',
    props: {
        options: [
            { text: 'Listed', value: '1' },
            { text: 'Delisted', value: '2' },
        ],
        shape: 'square',
        checkedColor: '#ee0a24',
        iconSize: '24px',
    }
}

Events Examples

Handle Selection Changes

js
const rule = {
    type: 'radio',
    title: 'Delivery Method',
    field: 'delivery',
    value: '1',
    props: {
        options: [
            { text: 'Express Delivery', value: '1' },
            { text: 'Store Pickup', value: '2' },
            { text: 'Same City Delivery', value: '3' },
        ],
    },
    on: {
        change: (name) => {
            console.log('Selection changed:', name);
        },
    },
}

Linkage Update After Selection

js
const rule = [
    {
        type: 'radio',
        title: 'Delivery Method',
        field: 'delivery',
        value: '1',
        props: {
            options: [
                { text: 'Express Delivery', value: '1' },
                { text: 'Store Pickup', value: '2' },
                { text: 'Same City Delivery', value: '3' },
            ],
        },
        inject: true,
        on: {
            change: ($inject, name) => {
                // Set freight by delivery method
                const freightMap = {
                    '1': 10,
                    '2': 0,
                    '3': 5,
                };
                $inject.api.setValue('freight', freightMap[name] || 0);
            },
        },
    },
    {
        type: 'stepper',
        title: 'Freight',
        field: 'freight',
        props: {
            disabled: true,
        },
    },
]

Complete configuration items:Vant_Radio

value :String | Number

Options

Field NameDescriptionField TypeRequiredDefault Value
valueParameter valueString,Numbertrue-
textField aliasStringtrue-
disabledSet to disabled stateBooleanfalsefalse

Props

ParameterDescriptionTypeDefault Value
disabledWhether to disable all radio buttonsbooleanfalse
directionLayout direction, optional value is horizontalstringvertical
icon-sizeIcon size for all radio buttons, default unit is pxnumber | string20px
checked-colorSelected state color for all radio buttonsstring#1989fa
shapeShape, optional values are square dotstringround

Events

Event NameDescriptionCallback Parameters
changeEvent triggered when bound value changesname: string

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.