Skip to content

debounce

防抖函数

基础用法

参数名参数类型是否必传参数说明
fnfunction需要防抖的函数
delaynumber延迟时间,单位为毫秒
ts
import { debounce } from '@lichang666/utils'

const inputHandler = debounce(() => {
  //do some things
}, 1000)

demo

输入值:
vue
<input v-model="inputValue" @input="inputHandler" />
<span>输入值:{{ showValue }}</span>

<script lang="ts" setup>
  import { debounce } from '@lichang666/utils'
  import { ref } from 'vue'
  const inputValue = ref('')
  const showValue = ref('')
  const inputHandler = debounce(() => {
    showValue.value = inputValue.value
  }, 1000)
</script>