Skip to content

Radio

The radio button has a selection and the user can only select one of the scenarios.

platform compatibility

App(vue)App(nvue)H5小程序VUE2VUE3

Basic usage

This component needs to be used with the radioGroup component, so that the user can get the selection status of the current radio group when operating Bind a variable to the radioGroup component through v-model, and the corresponding name will be selected

vue
<template>
  <wu-radio-group
    v-model="radiovalue1"
    placement="column"
    @change="groupChange"
  >
    <wu-radio
      :customStyle="{marginBottom: '8px'}"
      v-for="(item, index) in radiolist1"
      :key="index"
      :label="item.name"
      :name="item.name"
      @change="radioChange"
    >
    </wu-radio>
  </wu-radio-group>
</template>

<script>
export default {
	data() {
		return {
          // Basic case data
          radiolist1: [
            {
                name: 'JavaScript',
                disabled: false
            },
            {
                name: 'Python',
                disabled: false
            },
            {
                name: 'Java',
                disabled: false
            }, {
                name: 'C++',
                disabled: false
            }
          ],
          // If the v-model binding value of wu-radio-group is set to the name of a certain radio, it will be selected by default.
          radiovalue1: 'JavaScript',
		};
	},
	methods: {
      groupChange(n) {
        console.log('groupChange', n);
      },
      radioChange(n) {
        console.log('radioChange', n);
      }
	}
};
</script>
<template>
  <wu-radio-group
    v-model="radiovalue1"
    placement="column"
    @change="groupChange"
  >
    <wu-radio
      :customStyle="{marginBottom: '8px'}"
      v-for="(item, index) in radiolist1"
      :key="index"
      :label="item.name"
      :name="item.name"
      @change="radioChange"
    >
    </wu-radio>
  </wu-radio-group>
</template>

<script>
export default {
	data() {
		return {
          // Basic case data
          radiolist1: [
            {
                name: 'JavaScript',
                disabled: false
            },
            {
                name: 'Python',
                disabled: false
            },
            {
                name: 'Java',
                disabled: false
            }, {
                name: 'C++',
                disabled: false
            }
          ],
          // If the v-model binding value of wu-radio-group is set to the name of a certain radio, it will be selected by default.
          radiovalue1: 'JavaScript',
		};
	},
	methods: {
      groupChange(n) {
        console.log('groupChange', n);
      },
      radioChange(n) {
        console.log('radioChange', n);
      }
	}
};
</script>

Custom shape

You can set the radio box to be a square or a circle by setting shape to square or circle

html
<wu-radio-group v-model="value">
	<wu-radio shape="circle" label="围棋赌酒到天明"></wu-radio>
</wu-radio-group>
<wu-radio-group v-model="value">
	<wu-radio shape="circle" label="围棋赌酒到天明"></wu-radio>
</wu-radio-group>

disable radio

Set disabled to true to disable a component so that users cannot click it

html
<wu-radio-group v-model="value">
    <wu-radio :disabled="true" label="把酒问青天"></wu-radio>
</wu-radio-group>
<wu-radio-group v-model="value">
    <wu-radio :disabled="true" label="把酒问青天"></wu-radio>
</wu-radio-group>

Whether to prohibit clicking the prompt to select the radio

Set labelDisabled to true to disable clicking on the prompt to select the radio

html
<wu-radio-group v-model="value">
    <wu-radio :labelDisabled="true" label="把酒问青天"></wu-radio>
</wu-radio-group>
<wu-radio-group v-model="value">
    <wu-radio :labelDisabled="true" label="把酒问青天"></wu-radio>
</wu-radio-group>

Custom Colors

The color referred to here is the background color when radio is selected, and the parameter is activeColor

html
<wu-radio-group v-model="value">
	<wu-radio activeColor="red" label="一日不见兮,思之如狂"></wu-radio>
</wu-radio-group>
<wu-radio-group v-model="value">
	<wu-radio activeColor="red" label="一日不见兮,思之如狂"></wu-radio>
</wu-radio-group>

Horizontal arrangement

You can set the radioes to be arranged horizontally or vertically by setting placement to row or column

html
<wu-radio-group 
    v-model="value"
    placement="row">
	<wu-radio activeColor="red" label="一日不见兮,思之如狂"></wu-radio>
</wu-radio-group>
<wu-radio-group 
    v-model="value"
    placement="row">
	<wu-radio activeColor="red" label="一日不见兮,思之如狂"></wu-radio>
</wu-radio-group>

Horizontal two ends arrangement form

You can set the alignment of the radio icon to be left or right by setting iconPlacement to left or right

html
<wu-radio-group 
    v-model="value"
    iconPlacement="right">
	<wu-radio activeColor="red" label="一日不见兮,思之如狂"></wu-radio>
</wu-radio-group>
<wu-radio-group 
    v-model="value"
    iconPlacement="right">
	<wu-radio activeColor="red" label="一日不见兮,思之如狂"></wu-radio>
</wu-radio-group>

API

Radio Props

Note: Among radio and radio-group parameters with the same name, the radio parameter has a higher priority.

property namedescriptiontypedefault valueoptional values ​​
namethe name of the radioString / Number--
shapeshape, square is a square, circle is a circleStringsquaresquare / circle
disabledWhether to disableBoolean--
labelDisabledWhether to disable clicking on the prompt to select the radioString / Boolean--
activeColorThe color in the selected state, if this value is set, it will override the parent's activeColor valueString--
inactiveColorinactive colorString--
iconSizeThe size of the icon, in pxString / Number--
labelSizefont size of the label, in pxString / Number--
labellabel prompt text, because under nvue, the text directly slotted in, due to the special structure, the style cannot be modifiedString / Number--
sizeoverall sizeString / Number--
iconColoricon colorString--
labelColorthe color of the labelString--

RadioGroup Props

property namedescriptiontypedefault valueoptional values ​​
value / modelValueBinding valueString / Number / Boolean''-
disabledWhether to disable all radiosBooleanfalsetrue
shapeshape, circle-circle, square-squareStringcirclecircle / square
activeColorThe color in the selected state, if the child radio component sets this value, it will overwrite this valueString#2979ff-
inactiveColorInactive colorString#c8c9cc-
nameidentifierString--
sizeThe size of the entire component, default pxString / Number18-
placementlayout method, row-horizontal, column-verticalStringrowcolumn
labeltextString--
labelColorfont color of labelString#303133-
labelSizefont size of the label, in pxString / Number14-
labelDisabledWhether to disable clicking on the textBooleanfalsetrue / false
iconColoricon colorString#ffffff-
iconSizeThe size of the icon, in pxString / Number12-
borderBottomWhether to display an underline when vertically arranging columnsBooleanfalsetrue / false
iconPlacementThe alignment of the check icon, left-left, right-rightStringleftleft / right

Radio Event

method namedescriptioncallback parameters
changeTriggered when a radio state changes (selected state)name: name value passed through props

RadioGroup Event

method namedescriptioncallback parameters
changeTriggered when any radio state changesname: The value is the name value passed by radio through props