mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
refactor(front): replace Button with AsyncButton in FormButton component for async click handling
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user