Commit d3ec7a58ad96eda0db23a99614b65fa59602ec10
Committed by
GitHub
1 parent
83e52968
fix: 修复RadioButtonGroup组件返回值不正确的bug (#2513)
Showing
1 changed file
with
10 additions
and
4 deletions
src/components/Form/src/components/RadioButtonGroup.vue
... | ... | @@ -4,14 +4,14 @@ |
4 | 4 | <template> |
5 | 5 | <RadioGroup v-bind="attrs" v-model:value="state" button-style="solid"> |
6 | 6 | <template v-for="item in getOptions" :key="`${item.value}`"> |
7 | - <RadioButton :value="item.value" :disabled="item.disabled"> | |
7 | + <RadioButton :value="item.value" :disabled="item.disabled" @click="handleClick(item)"> | |
8 | 8 | {{ item.label }} |
9 | 9 | </RadioButton> |
10 | 10 | </template> |
11 | 11 | </RadioGroup> |
12 | 12 | </template> |
13 | 13 | <script lang="ts"> |
14 | - import { defineComponent, PropType, computed } from 'vue'; | |
14 | + import { defineComponent, PropType, computed, ref } from 'vue'; | |
15 | 15 | import { Radio } from 'ant-design-vue'; |
16 | 16 | import { isString } from '/@/utils/is'; |
17 | 17 | import { useRuleFormItem } from '/@/hooks/component/useFormItem'; |
... | ... | @@ -35,10 +35,12 @@ |
35 | 35 | default: () => [], |
36 | 36 | }, |
37 | 37 | }, |
38 | + emits: ['change'], | |
38 | 39 | setup(props) { |
39 | 40 | const attrs = useAttrs(); |
41 | + const emitData = ref<any[]>([]); | |
40 | 42 | // Embedded in the form, just use the hook binding to perform form verification |
41 | - const [state] = useRuleFormItem(props); | |
43 | + const [state] = useRuleFormItem(props, 'value', 'change', emitData); | |
42 | 44 | |
43 | 45 | // Processing options value |
44 | 46 | const getOptions = computed((): OptionsItem[] => { |
... | ... | @@ -51,7 +53,11 @@ |
51 | 53 | return options.map((item) => ({ label: item, value: item })) as OptionsItem[]; |
52 | 54 | }); |
53 | 55 | |
54 | - return { state, getOptions, attrs }; | |
56 | + function handleClick(...args) { | |
57 | + emitData.value = args; | |
58 | + } | |
59 | + | |
60 | + return { state, getOptions, attrs, handleClick }; | |
55 | 61 | }, |
56 | 62 | }); |
57 | 63 | </script> | ... | ... |