vue-admin-core
Version:
A Component Library for Vue 3
36 lines (33 loc) • 821 B
JavaScript
import { watch, toRef, toValue, ref } from 'vue';
const useAutoRunPlugin = (fetchInstance, { manual, ready = ref(true), defaultParams = [], refreshDeps = [], refreshDepsAction }) => {
watch(toRef(ready), () => {
if (!manual && toValue(ready)) {
fetchInstance.run(...defaultParams);
}
});
watch(refreshDeps, () => {
if (!manual) {
if (refreshDepsAction) {
refreshDepsAction();
} else {
fetchInstance.refresh();
}
}
});
return {
onBefore: () => {
if (!ready.value) {
return {
stopNow: true
};
}
}
};
};
useAutoRunPlugin.onInit = ({ ready = ref(true), manual }) => {
return {
loading: !manual && ready.value
};
};
export { useAutoRunPlugin as default };
//# sourceMappingURL=useAutoRunPlugin.mjs.map