import { ref } from "vue"

/**
 * 包装一个工作函数Promise用于控制按钮的loading状态
 */
export function useLoadingAction(promise: () => Promise<any>) {
  const loading = ref(false);
  return {
    loading,
    onClick: () => {
      loading.value = true;
      promise().then(() => {
        loading.value = false;
      }).catch(() => {
        loading.value = false;
      })
    }
  }
}