debounce
防抖函数
基础用法
参数名 | 参数类型 | 是否必传 | 参数说明 |
---|---|---|---|
fn | function | 是 | 需要防抖的函数 |
delay | number | 是 | 延迟时间,单位为毫秒 |
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>