refactor(front): replace Button with AsyncButton in FormButton component for async click handling

This commit is contained in:
keven1024
2025-05-14 15:07:15 +08:00
parent 4673a82efe
commit 4c57afd476

View File

@@ -1,13 +1,13 @@
<template>
<Button type="button" @click="(e) => {
e.preventDefault()
emit('click', form)
<AsyncButton type="button" @click="async (e) => {
e?.preventDefault()
await props.onClick?.(form)
}" :disabled="!isValid">
<slot />
</Button>
</AsyncButton>
</template>
<script setup lang="ts">
import { Button } from '~/components/ui/button'
import { AsyncButton } from '~/components/ui/button'
import { useFormContext } from 'vee-validate'
const form = useFormContext()
@@ -18,7 +18,9 @@ watchEffect(async () => {
isValid.value = valid
})
const emit = defineEmits<{
(e: 'click', form: ReturnType<typeof useFormContext>): void
}>()
const props = withDefaults(defineProps<{
onClick?: (form: ReturnType<typeof useFormContext>) => Promise<void>
}>(), {
onClick: async () => {}
})
</script>