Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created August 5, 2020 00:34
Show Gist options
  • Save toast38coza/ef4252461d49f87fa8670794ecf5d2b2 to your computer and use it in GitHub Desktop.
Save toast38coza/ef4252461d49f87fa8670794ecf5d2b2 to your computer and use it in GitHub Desktop.
A simple way to do a debounce with Vue (not dependencies required)
<template>
<input type=text v-model='value' @kepup='debounceExpensiveMethod' />
</template>
<script>
export default {
name: 'SomeComponent',
data () {
return {
timeout: null
}
},
methods: {
debounceExpensiveMethod () {
if (this.timeout) {
window.clearTimeout(this.timeout)
}
this.timeout = window.setTimeout(this.expensiveMethod, 1000)
},
expensiveMethod () {
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment