Created
January 5, 2020 01:57
-
-
Save saitergun/e08a365238f1fd82e7d8904a5a306f8c to your computer and use it in GitHub Desktop.
vue.js debouncing method
This file contains hidden or 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
<template> | |
<input type="text" v-model="query" @input="search" /> | |
</template> | |
<script> | |
export default { | |
name: 'Debounce', | |
data: () => ({ | |
query: null, | |
debounceTimeout: false, | |
}), | |
methods: { | |
search() { | |
window.clearTimeout(this.debounceTimeout); | |
this.debounceTimeout = setTimeout(() => { | |
console.log('debounced!'); | |
}, 500); | |
}, | |
}, | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment