Skip to content

Radio

示例

基本使用

<template>
  <div>
    <SuperRadio v-model="value" :options="options"></SuperRadio>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const value = ref()

const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

不同类型展示状态

<template>
  <div>
    <div>默认样式: type: radion</div>
    <SuperRadio v-model="value" type="radio" :options="options"></SuperRadio>
    <div>按钮样式: type: button</div>
    <SuperRadio v-model="value" type="button" :options="options"></SuperRadio>
    <div>边框样式: border</div>
    <SuperRadio v-model="value" border :options="options"></SuperRadio>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const value = ref()

const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

label-添加前缀

<template>
  <div>
    <div>默认前缀: prefix</div>
    <SuperRadio v-model="value" :options="options" prefix></SuperRadio>
    <div>自定义前缀: prefix="测试前缀-"</div>
    <SuperRadio v-model="value" :options="options" prefix="测试前缀-"></SuperRadio>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const value = ref()

const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

禁用状态

<template>
  <div>
    <div>全部禁用</div>
    <SuperRadio v-model="value" :options="options" disabled></SuperRadio>
    <div>选项禁用</div>
    <SuperRadio v-model="value" :options="options" :disabled="isDisabled"></SuperRadio>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const value = ref()

const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]

const isDisabled = (item: { value: string }) => item.value === '2'
</script>

包含/排除选项

<template>
  <div>
    <div>包含选项: include="['1', '3']</div>
    <SuperRadio v-model="value" :options="options" :include="['1', '3']"></SuperRadio>
    <div>排除选项: exclude="['1', '3']</div>
    <SuperRadio v-model="value" :options="options" :exclude="['1', '3']"></SuperRadio>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";

const value = ref()

const options = [
  { label: '选项1', value: '1' },
  { label: '选项2', value: '2' },
  { label: '选项3', value: '3' },
]
</script>

API

Props

参数说明类型可选值默认值
type按钮样式string'radio' | 'button'radion
size尺寸stringsmall | default | largedefault
border是否显示边框booleantrue|falsefalse
labelKey自定义label字段属性名string-label
valueKey自定义value字段属性名string-value
prefix是否使用前缀boolean | ((item: any) => boolean)--
disabled是否禁用boolean | ((item: any) => boolean)--
include包含的选项Array<string | number>--
exclude排除的选项Array<string | number>--

Slots

插槽名说明
default自定义默认内容