Skip to content

Instantly share code, notes, and snippets.

@gms64
Created August 17, 2020 19:46
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 gms64/c1f3d3f41c7969607dd7d17f95d99e3e to your computer and use it in GitHub Desktop.
Save gms64/c1f3d3f41c7969607dd7d17f95d99e3e to your computer and use it in GitHub Desktop.
Runs an function after user is finished typing
<template>
<div>
<h1>Fire After Finished Typing</h1>
<hr>
<input v-model="typingInput" type="text" placeholder="Type Something Here" v-on:keyup="isTyping">
<p>{{showResult}}</p>
</div>
</template>
<script>
let typingTimer; // Init Timer Variable
let doneTypingInterval = 500; // Will fire 0.5s after last keypress
export default {
data() {
return {
typingInput: '',
showResult: ''
}
},
methods: {
isTyping() {
// Clears any previous timer
clearTimeout(typingTimer);
// Starts new timer that runs this.doneTyping
typingTimer = setTimeout(this.doneTyping,
doneTypingInterval);
},
doneTyping() {
this.showResult = this.typingInput
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment