import { ref } from 'vue' import type { Ref } from 'vue' export function useLoading(initial = false): { isLoading: Ref startLoading: () => void stopLoading: () => void withLoading: (fn: () => Promise) => Promise } { const isLoading = ref(initial) const startLoading = () => { isLoading.value = true } const stopLoading = () => { isLoading.value = false } const withLoading = async (fn: () => Promise): Promise => { isLoading.value = true try { return await fn() } finally { isLoading.value = false } } return { isLoading, startLoading, stopLoading, withLoading } }