Skip to content
On this page

useThrottleFn

处理节流函数

Demo

num: 0

Usage

html
<template>
  <div>
    <p>num: {{ num }}</p>

    <button @click="run">执行函数 +1</button>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { useThrottleFn } from '@morehook/core'

const num = ref(0)
const { run } = useThrottleFn(() => {
  num.value++
}, 1000)
</script>

Type Declarations

typescript
type Fn = (...params: any[]) => any
/**
 * 处理节流函数
 * @param fn 待执行函数
 * @param delay 节流设定时间 (默认 1000)
 * @param runLastFn 是否在节流过期时执行最后一次被拦住的方法
 * @returns 包装后的函数
 */
export declare function useThrottleFn(
  fn: Fn,
  delay?: number,
  runLastFn?: boolean
): {
  run: () => void
}

Source

SourceDemoDocs