VEUI

VEUI on GitHub
Play!中文

Radio

Examples

Size variants

Available values for the ui prop: s / m.

Edit this demo on GitHubEdit
<template>
<article>
  <section>
    <veui-radio
      v-model="size"
      class="radio"
      value="m"
      :ui="size"
      name="size"
    >
      Normal size
    </veui-radio>
    <veui-radio
      v-model="size"
      class="radio"
      value="s"
      :ui="size"
      name="size"
    >
      Small size
    </veui-radio>
  </section>
</article>
</template>

<script>
import { Radio } from 'veui'

export default {
  components: {
    'veui-radio': Radio
  },
  data () {
    return {
      size: 'm'
    }
  }
}
</script>

<style lang="less" scoped>
.radio {
  margin-right: 20px;
}

section {
  margin-bottom: 20px;
}
</style>

Model values

You can modify the value of v-model when selected by setting the value prop.

Selected: -

Edit this demo on GitHubEdit
<template>
<article>
  <veui-radio
    v-for="({ value, label }) in flavors"
    :key="value"
    v-model="flavor"
    class="radio"
    :value="value"
  >
    {{ label }}
  </veui-radio>
  <p>Selected: {{ flavorLabelMap[flavor] || '-' }}</p>
</article>
</template>

<script>
import { Radio } from 'veui'

export default {
  components: {
    'veui-radio': Radio
  },
  data () {
    return {
      flavor: null,
      flavors: [
        { value: 'LATTE', label: 'Latte' },
        { value: 'MOCHA', label: 'Mocha' },
        { value: 'AMERICANO', label: 'Americano' }
      ]
    }
  },
  computed: {
    flavorLabelMap () {
      return this.flavors.reduce((map, { value, label }) => {
        map[value] = label
        return map
      }, {})
    }
  }
}
</script>

<style lang="less" scoped>
.radio {
  margin-right: 20px;
}
</style>

API

Props

NameTypeDefaultDescription
uistring-

Predefined styles.

ValueDescription
sSmall size style.
mMedium size style.
checkedbooleanfalse

.sync

Whether the component is in the selected state.

value*trueThe value corresponding to the selected state.
disabledbooleanfalseWhether the component is disabled.
readonlybooleanfalseWhether the component is read-only.

Slots

NameDescription
defaultThe description text of the radio button. It will be selected when clicked. No default content.

Events

NameDescription
changeTriggered when the user switches the selected state. The callback parameter is (checked: boolean). checked indicates whether it is currently selected.
input

v-model

Triggered after the selection state has changed. The callback parameter is (val: *). val is the current value of v-model. Unlike the change event, the input event will also be triggered when the data operation causes the state to change.

In addition, Radio supports the following native events:

auxclick, click, contextmenu, dblclick, mousedown, mouseenter, mouseleave, mousemove, mouseover, mouseout, mouseup, select, wheel, keydown, keypress, keyup, focus, blur, focusin, focusout.

The callback parameters are all corresponding native event objects.

Edit this page on GitHubEdit
© Baidu, Inc. 2024