Created
October 6, 2020 21:36
-
-
Save seanpierce/a890b8a2c56cbd8b634ee476b9e59ca3 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
<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