I am attempting to detect when the user begins typing and stops typing using the debounce
function. I experimented with Lodash and Underscore.js.
On my textArea
v-on:keyup="handler($event)"
handler: function(e) {
this.e = e
if(this.canPublish) {
this.setCanNotPublish()
this.doStuff()
}
var debounceFunction = _.debounce(this.doneTyping(), 5000)
debounceFunction(e)
},
I am becoming quite frustrated with this issue. I successfully achieved it in pure JavaScript, but with Vue.js, where it involves v-on events, data, methods, etc., I'm facing challenges.
Method doneTyping
doneTyping: function () {
console.log('done typing....')
}
}
Method doStuff
doStuff: function () {
console.log('started typing....')
}
The desired functionality is as follows: initially, when the user starts typing in the textArea, doStuff should be triggered. If the user continues typing within a 5-second interval, doStuff won't be activated again due to the boolean canPublish. When the user stops typing, the debounce function finishes its delay, and doneTyping is executed.