Skip to content

Instantly share code, notes, and snippets.

@seanpierce
Created October 6, 2020 21:36
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 seanpierce/a890b8a2c56cbd8b634ee476b9e59ca3 to your computer and use it in GitHub Desktop.
Save seanpierce/a890b8a2c56cbd8b634ee476b9e59ca3 to your computer and use it in GitHub Desktop.
<template>
<div>
<input type="text" v-model="userInput" @change="submit()">
</div>
</template>
<script>
data() {
return {
userInput: "",
bouncing: null
}
},
methods: {
submit() {
if (this.bouncing) {
clearTimeout(this.bouncing)
this.bouncing = null
}
this.bouncing = setTimeout(() => {
// call an API through a store dispatch, axios, service class, etc.
this.$store.dispatch("someAPICall", this.userInput)
// reset the bouncing variable
this.bouncing = false
}, 3000)
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment