perf: 优化ApiRadioGroup回调函数change参数 (#2512)

This commit is contained in:
lzdjack 2023-01-31 18:03:11 +08:00 committed by GitHub
parent 4d6f24d053
commit 83e529681a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 6 deletions

View File

@ -2,12 +2,17 @@
* @Description:It is troublesome to implement radio button group in the form. So it is extracted independently as a separate component
-->
<template>
<RadioGroup v-bind="attrs" v-model:value="state" button-style="solid" @change="handleChange">
<RadioGroup v-bind="attrs" v-model:value="state" button-style="solid">
<template v-for="item in getOptions" :key="`${item.value}`">
<RadioButton v-if="props.isBtn" :value="item.value" :disabled="item.disabled">
<RadioButton
v-if="props.isBtn"
:value="item.value"
:disabled="item.disabled"
@click="handleClick(item)"
>
{{ item.label }}
</RadioButton>
<Radio v-else :value="item.value" :disabled="item.disabled">
<Radio v-else :value="item.value" :disabled="item.disabled" @click="handleClick(item)">
{{ item.label }}
</Radio>
</template>
@ -62,7 +67,7 @@
const attrs = useAttrs();
const { t } = useI18n();
// Embedded in the form, just use the hook binding to perform form verification
const [state] = useRuleFormItem(props);
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
// Processing options value
const getOptions = computed(() => {
@ -120,11 +125,11 @@
emit('options-change', unref(getOptions));
}
function handleChange(_, ...args) {
function handleClick(...args) {
emitData.value = args;
}
return { state, getOptions, attrs, loading, t, handleChange, props };
return { state, getOptions, attrs, loading, t, handleClick, props };
},
});
</script>