-
-
Save parzibyte/869f7beb2f324ca2b642488298b35aaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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