vue-data-fetcher
Version:
Vue Data Fetcher is a collection of composable functions that provide utility functionalities for common tasks in Vue.js projects. This package is designed to simplify and streamline the development process by encapsulating complex logic into reusable com
48 lines (47 loc) • 909 B
JavaScript
import { ref as t, onBeforeMount as u } from "vue";
function i(l, c) {
const n = t(null), e = t(!1), r = t(null), s = async () => {
e.value = !0;
try {
const a = await l(c);
n.value = a;
} catch (a) {
r.value = a.message || "An error occurred.";
} finally {
e.value = !1;
}
};
return u(() => {
s();
}), {
responseData: n,
loading: e,
error: r,
fetchData: s
};
}
function v(l, c, n) {
const e = t(null), r = t(!0), s = t(null), a = async () => {
r.value = !0;
try {
const o = await l(c);
n ? e.value = n(o) : e.value = o;
} catch (o) {
s.value = o.message || "An error occurred.";
} finally {
r.value = !1;
}
};
return u(() => {
a();
}), {
responseData: e,
loading: r,
error: s,
fetchData: a
};
}
export {
v as useDataFetcherFind,
i as useDataFetcherList
};