vhook

useDebounceFn

生成带防抖功能的函数

API

const debounceFn = useDebounceFn(fn, delay)

Params

参数名描述类型默认值
fn需要添加防抖功能的函数(…rest: any[]) => any
delay延时时间number200

Example

Code

<template>
  <p>疯狂点击按钮,最后停下3s才会执行回调</p>
  <button @click="onClick">click</button>
</template>

<script>
  import { useDebounceFn } from 'vhook'
  export default {
    setup () {
      const onClick = useDebounceFn(() => {
        alert('click')
      }, 3000)
      return {
        onClick
      }
    }
  }
</script>