Skip to content

Radio 单选框

在一组备选项中进行单选

基础用法

由于选项默认可见,不宜过多,若选项过多,建议使用 Select 选择器。

<template>
  <s-radio v-model="radio" value="1">备选项</s-radio>
  <s-radio v-model="radio" value="2">备选项</s-radio>
</template>

<script setup>
import SRadio from '@/components/Radio'
import { ref } from 'vue'
const radio = ref('1')
</script>

<style lang="scss" scoped></style>

禁用状态

单选框不可用的状态。

<template>
  <s-radio disabled v-model="radio" value="1">备选项</s-radio>
  <s-radio disabled v-model="radio" value="2">备选项</s-radio>
</template>

<script setup>
import SRadio from '@/components/Radio'
import { ref } from 'vue'
const radio = ref('1')
</script>

<style lang="scss" scoped></style>

单选框组

适用于在多个互斥的选项中选择的场景

<template>
  <s-radio-group v-model="radio">
    <s-radio value="1">备选项</s-radio>
    <s-radio value="2">备选项</s-radio>
    <s-radio value="3">备选项</s-radio>
  </s-radio-group>
</template>

<script setup>
import SRadio, { SRadioGroup} from '@/components/Radio'
import { ref } from 'vue'
const radio = ref('1')
</script>

<style lang="scss" scoped></style>

按钮样式

按钮样式的单选组合。

<template>
  <div>
    <s-radio-group v-model="radio1">
      <s-radio-button value="上海"></s-radio-button>
      <s-radio-button value="北京"></s-radio-button>
      <s-radio-button value="广州"></s-radio-button>
      <s-radio-button value="深圳"></s-radio-button>
    </s-radio-group>
  </div>
  <div style="margin-top: 20px">
    <s-radio-group v-model="radio2" size="medium">
      <s-radio-button value="上海" ></s-radio-button>
      <s-radio-button value="北京"></s-radio-button>
      <s-radio-button value="广州"></s-radio-button>
      <s-radio-button value="深圳"></s-radio-button>
    </s-radio-group>
  </div>
  <div style="margin-top: 20px">
    <s-radio-group v-model="radio3" size="small">
      <s-radio-button value="上海"></s-radio-button>
      <s-radio-button value="北京" disabled ></s-radio-button>
      <s-radio-button value="广州"></s-radio-button>
      <s-radio-button value="深圳"></s-radio-button>
    </s-radio-group>
  </div>
  <div style="margin-top: 20px">
    <s-radio-group v-model="radio4" disabled size="mini">
      <s-radio-button value="上海"></s-radio-button>
      <s-radio-button value="北京"></s-radio-button>
      <s-radio-button value="广州"></s-radio-button>
      <s-radio-button value="深圳"></s-radio-button>
    </s-radio-group>
  </div>
</template>

<script setup>
import{ SRadioGroup,SRadioButton} from '@/components/Radio'
import { ref } from 'vue'
const radio1 = ref('上海')
const radio2 = ref('上海')
const radio3 = ref('上海')
const radio4= ref('上海')
</script>

<style lang="scss" scoped></style>

带有边框

设置border属性可以渲染为带有边框的单选框。

<template>
  <div>
    <s-radio v-model="radio1" value="1" border>备选项1</s-radio>
    <s-radio v-model="radio1" value="2" border>备选项2</s-radio>
  </div>
  <div style="margin-top: 20px">
    <s-radio v-model="radio2" value="1" border size="medium">备选项1</s-radio>
    <s-radio v-model="radio2" value="2" border size="medium">备选项2</s-radio>
  </div>
  <div style="margin-top: 20px">
    <s-radio-group v-model="radio3" size="small">
      <s-radio value="1" border>备选项1</s-radio>
      <s-radio value="2" border disabled>备选项2</s-radio>
    </s-radio-group>
  </div>
  <div style="margin-top: 20px">
    <s-radio-group v-model="radio4" size="mini" disabled>
      <s-radio value="1" border>备选项1</s-radio>
      <s-radio value="2" border>备选项2</s-radio>
    </s-radio-group>
  </div>
</template>

<script setup>
import SRadio, { SRadioGroup} from '@/components/Radio'
import { ref } from 'vue'
const radio1 = ref('1')
const radio2 = ref('1')
const radio3 = ref('1')
const radio4 = ref('1')
</script>

<style lang="scss" scoped></style>

API

Radio Attributes

参数说明类型可选值默认值
value/ v-model选中状态的值string / number / boolean
label选项的标识符string
disabled是否禁用booleanfalse
border是否显示边框booleanfalse
size单选框的尺寸stringmedium / small / mini
name原生 name 属性string
checked当前是否选中booleanfalse

Radio Events

事件名称说明回调参数
input绑定值变化时触发的事件选中的 Radio label 值

Radio-group Attributes

参数说明类型可选值默认值
value/ v-model选中项的绑定值string / number / boolean
size单选框的尺寸stringmedium / small / mini
disabled是否禁用booleanfalse
text-color按钮形式的 Radio 激活时的文本颜色string#ffffff
fill按钮形式的 Radio 激活时的填充色和边框色string#409EFF

Radio-group Events

事件名称说明回调参数
input绑定值变化时触发的事件选中的 Radio label 值

Radio-button Attributes

参数说明类型可选值默认值
labelRadio 的 valuestring
disabled是否禁用booleanfalse
name原生 name 属性string

Released under the MIT License.