디바운싱은 주로 ajax 검색에 자주 쓰입니다.
쓰로틀링은 스크롤을 올리거나 내릴 때 보통 사용합니다.
<template>
<div>
<input
:value="inputText"
@input="
(e) => {
inputText = e.target.value;
changeHandler();
debounceFunc(e.target.value);
}
"
/>
</div>
</template>
<script setup lang="ts">
import { Ref, ref, watch } from "vue";
import _, { debounce } from "underscore";
const inputText: Ref<string> = ref<string>("");
const changeHandler = () => {
console.log("일반 : " + inputText.value);
};
const debounceFunc = _.debounce((text: string) => {
console.log("디바운스 : " + text);
}, 500);
</script>
<style scoped></style>