forked from fdzcxy212206413/gsl_grs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
666 B
29 lines
666 B
1 month ago
|
import { ref, onMounted, watch } from 'vue';
|
||
|
|
||
|
const useThrottleRender = (loading, throttle = 0) => {
|
||
|
if (throttle === 0)
|
||
|
return loading;
|
||
|
const throttled = ref(false);
|
||
|
let timeoutHandle = null;
|
||
|
const dispatchThrottling = () => {
|
||
|
if (timeoutHandle) {
|
||
|
clearTimeout(timeoutHandle);
|
||
|
}
|
||
|
timeoutHandle = setTimeout(() => {
|
||
|
throttled.value = loading.value;
|
||
|
}, throttle);
|
||
|
};
|
||
|
onMounted(dispatchThrottling);
|
||
|
watch(() => loading.value, (val) => {
|
||
|
if (val) {
|
||
|
dispatchThrottling();
|
||
|
} else {
|
||
|
throttled.value = val;
|
||
|
}
|
||
|
});
|
||
|
return throttled;
|
||
|
};
|
||
|
|
||
|
export { useThrottleRender };
|
||
|
//# sourceMappingURL=index.mjs.map
|