Skip to content

DictRadio 字典单选

基于系统字典数据渲染的单选组组件,自动从后端获取字典数据并缓存。

基础用法

vue
<template>
  <DictRadio v-model="form.gender" dictType="sys_user_gender" />
</template>

<script setup>
import { DictRadio } from '@/components/Dict'

const form = ref({
  gender: ''
})
</script>

Props

参数类型默认值说明
modelValuestring | number-绑定值
dictTypestring-字典类型(必填)

Events

事件名说明回调参数
update:modelValue值改变时触发选中的值
change选择改变时触发选中的值

完整示例

vue
<template>
  <el-form :model="form" label-width="100px">
    <el-form-item label="性别">
      <DictRadio v-model="form.gender" dictType="sys_user_gender" />
    </el-form-item>
    
    <el-form-item label="状态">
      <DictRadio v-model="form.status" dictType="sys_user_status" />
    </el-form-item>
  </el-form>
</template>

<script setup>
import { ref } from 'vue'
import { DictRadio } from '@/components/Dict'

const form = ref({
  gender: '1',
  status: '0'
})
</script>

注意事项

  1. 字典类型dictType 对应后端字典类型表的 dict_type 字段
  2. 数据缓存:组件会自动缓存字典数据,避免重复请求
  3. 值类型:组件会自动识别字典值是字符串还是数字

相关组件

基于 MIT 许可发布