mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 07:08:02 +00:00
30 lines
623 B
Vue
30 lines
623 B
Vue
<script setup lang="ts">
|
|
import { Button } from '@/components/ui/button'
|
|
const isLoading = ref(false)
|
|
|
|
const props = withDefaults(defineProps<{
|
|
disabled?: boolean
|
|
onClick?: (event?: Event) => Promise<void>
|
|
}>(), {
|
|
disabled: false,
|
|
onClick: async () => {}
|
|
})
|
|
|
|
const handleClick = async (event?: Event) => {
|
|
if (isLoading.value) return
|
|
|
|
isLoading.value = true
|
|
try {
|
|
await props.onClick?.(event)
|
|
}finally {
|
|
isLoading.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<Button :onClick="handleClick" :disabled="isLoading || disabled">
|
|
<slot />
|
|
</Button>
|
|
</template>
|