my view:
ns-input#filterName(type="text", v-model="filterName", @keyup="searchTimeOut()")
in my vue code:
getUsers() {
   .
   .
   .
   API.users.index(params).then(blabla);
   .
   .
   .
},
searchTimeOut() {
  let timeout = null;
  clearTimeout(timeout);
  // Make a new timeout set to go off in 800ms
  timeout = setTimeout(() => {
    this.getUsers();
    console.log("hi")
  }, 800);
},
I want call getUsers() only once after i stop typing and 800 ms. Right now, i'm calling getUsers() every time i write a letter.
You drop this.timer value before clearing the interval. Do this instead:
searchTimeOut() {  
    if (this.timer) {
        clearTimeout(this.timer);
        this.timer = null;
    }
    this.timer = setTimeout(() => {
        // your code
    }, 800);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With