'use strict';

var vue = require('vue');
var core = require('@vueuse/core');

const useLoading = (fn) => {
  const isLoading = vue.ref(false);
  const data = vue.ref();
  const getDataHook = core.createEventHook();
  const getDataFinally = async () => {
    if (!isLoading.value) {
      return;
    }
    return new Promise((resolve) => {
      getDataHook.on(resolve);
    });
  };
  const exec = async (...args) => {
    isLoading.value = true;
    try {
      const result = await fn(...args);
      data.value = result;
      return result;
    } finally {
      isLoading.value = false;
      getDataHook.trigger();
    }
  };
  return {
    isLoading,
    exec,
    getDataFinally
    // 获取数据完成
  };
};

exports.useLoading = useLoading;
//# sourceMappingURL=index.js.map
