Skip to content

Instantly share code, notes, and snippets.

@Antoinebr
Last active December 31, 2017 18:59
Show Gist options
  • Save Antoinebr/47e129863074934617c002fa7af848c8 to your computer and use it in GitHub Desktop.
Save Antoinebr/47e129863074934617c002fa7af848c8 to your computer and use it in GitHub Desktop.
debounce JavaScript Vue

Install

npm install debounce 

Require in Vue

import debounce from 'debounce';
 methods: {

      count : debounce( () => {

        fetch(`${API_URL}/wp-json/elastic/search/?query=${this.searchQuery}~`)
        .then( (response) => response.json() )
        .then( (res) => {

          console.log('TOTAL RES ', res.hits.total);
          this.total = res.hits.total;

         }).catch( (err) => console.log('Rejected ',err) );

      }, 500 ),
     
     }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment