Created
August 17, 2020 19:46
-
-
Save gms64/c1f3d3f41c7969607dd7d17f95d99e3e to your computer and use it in GitHub Desktop.
Runs an function after user is finished typing
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> | |
<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