ivue-material-plus
Version:
A high quality UI components Library with Vue.js
33 lines (30 loc) • 688 B
JavaScript
import { ref, watch, onMounted } from 'vue';
const useThrottleRender = (loading, throttle = 0) => {
if (throttle === 0) {
return loading;
}
const throttled = ref(false);
let setTimeout = 0;
const throttlingHandle = () => {
if (setTimeout) {
clearTimeout(setTimeout);
}
setTimeout = window.setTimeout(() => {
throttled.value = loading.value;
}, throttle);
};
watch(
() => loading.value,
(value) => {
if (value) {
throttlingHandle();
} else {
throttled.value = value;
}
}
);
onMounted(throttlingHandle);
return throttled;
};
export { useThrottleRender };
//# sourceMappingURL=index.mjs.map