Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active October 28, 2021 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/869f7beb2f324ca2b642488298b35aaf to your computer and use it in GitHub Desktop.
Save parzibyte/869f7beb2f324ca2b642488298b35aaf to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Debounce con Vue - By Parzibyte</title>
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<div id="app">
<input v-model="busqueda" type="text" @keyup="realizarBusqueda()">
</div>
<script>
const debounce = (callback, wait) => {
let timerId;
return (...args) => {
clearTimeout(timerId);
timerId = setTimeout(() => {
callback(...args);
}, wait);
};
};
new Vue({
el: "#app",
data: () => ({
busqueda: "",
}),
created() {
this.realizarBusqueda = debounce(() => {
console.log("Realizamos la búsqueda!");
}, 500);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment