↖️ Show all posts

Debounce in Vue2

I found this very easy and indenpendent solution on StackOverflow (here).

// in your component
data() {
  return {
    timeoutScroll: undefined,
  }
}
methods: {
  handleScroll: function() {
    if (this.timeoutScroll) 
      clearTimeout(this.timeoutScroll); 

    this.timeoutScroll = setTimeout(() => {
      // your action here
    }, 200); // delay
  }
},

destroyed() { 
  clearInterval(this.timeout) 
}

No dependencies and easy to keep in mind - but I know I will get back here once every few weeks 🤫


⬅️ Read previous Read next ➡️