Skip to content

Instantly share code, notes, and snippets.

@saitergun
Created January 5, 2020 01:57
Show Gist options
  • Save saitergun/e08a365238f1fd82e7d8904a5a306f8c to your computer and use it in GitHub Desktop.
Save saitergun/e08a365238f1fd82e7d8904a5a306f8c to your computer and use it in GitHub Desktop.
vue.js debouncing method
<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