useThrottle

useThrottle 用于处理节流值

基础用法

<template>
  <p>Count: {{ count }}</p>

  <button @click="handleClick">Increment</button>
  <p>throttledSetCount:{{ throttledSetCount }}</p>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useThrottle } from 'hooks-vue3';
const count = ref<number>(0);
const handleClick = () => {
  count.value = count.value + 1;
};
const throttledSetCount = useThrottle<number>(count, {
  wait: 1000,
});
</script>
l

API

import type { ThrottleSettings } from 'lodash-es/throttle';
interface UseThrottleOptions extends ThrottleSettings {
  wait?: number;
}
const throttleValue = useThrottle(value:T,{ wait: Options });

参数

  • value (T): 要节流的值。

  • [wait=0] (number): 需要节流的毫秒。

  • [options=] (Object): 选项对象

  • [options.leading=false] (boolean): 指定调用在节流开始前。

  • [options.trailing=true] (boolean): 指定调用在节流结束后。

Last updated