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,14 +4,14 @@ | ||
4 | <template> | 4 | <template> |
5 | <RadioGroup v-bind="attrs" v-model:value="state" button-style="solid"> | 5 | <RadioGroup v-bind="attrs" v-model:value="state" button-style="solid"> |
6 | <template v-for="item in getOptions" :key="`${item.value}`"> | 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 | {{ item.label }} | 8 | {{ item.label }} |
9 | </RadioButton> | 9 | </RadioButton> |
10 | </template> | 10 | </template> |
11 | </RadioGroup> | 11 | </RadioGroup> |
12 | </template> | 12 | </template> |
13 | <script lang="ts"> | 13 | <script lang="ts"> |
14 | - import { defineComponent, PropType, computed } from 'vue'; | 14 | + import { defineComponent, PropType, computed, ref } from 'vue'; |
15 | import { Radio } from 'ant-design-vue'; | 15 | import { Radio } from 'ant-design-vue'; |
16 | import { isString } from '/@/utils/is'; | 16 | import { isString } from '/@/utils/is'; |
17 | import { useRuleFormItem } from '/@/hooks/component/useFormItem'; | 17 | import { useRuleFormItem } from '/@/hooks/component/useFormItem'; |
@@ -35,10 +35,12 @@ | @@ -35,10 +35,12 @@ | ||
35 | default: () => [], | 35 | default: () => [], |
36 | }, | 36 | }, |
37 | }, | 37 | }, |
38 | + emits: ['change'], | ||
38 | setup(props) { | 39 | setup(props) { |
39 | const attrs = useAttrs(); | 40 | const attrs = useAttrs(); |
41 | + const emitData = ref<any[]>([]); | ||
40 | // Embedded in the form, just use the hook binding to perform form verification | 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 | // Processing options value | 45 | // Processing options value |
44 | const getOptions = computed((): OptionsItem[] => { | 46 | const getOptions = computed((): OptionsItem[] => { |
@@ -51,7 +53,11 @@ | @@ -51,7 +53,11 @@ | ||
51 | return options.map((item) => ({ label: item, value: item })) as OptionsItem[]; | 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 | </script> | 63 | </script> |