dimanche 12 janvier 2020

How to do "submit form after user stop typing" in vuejs2

I have a search module in which: when a user stop typing it should search the name.

What I think the solution is to do a timeout when a user keyup. reference

<input type="text" @keyup="textSearch($event)">

textSearch(e){
    var timer;
    clearTimeout(timer);

    timer = setTimeout(() => {
        alert('searching...');
    }, 2500);
}

The code were all working, the problem is why when I type 3 character in just 1 second it pops out 3 alerts? I expect there should be one pop-out since it waits for 2.5 seconds.

Is there something wrong with the code? Need help Sirs



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire