0

I have:

async search() {

How can I implement lo dash's denounce? I've tried:

async search: _.debounce(function () {

But with no luck.

panthro
  • 22,779
  • 66
  • 183
  • 324

1 Answers1

1

Try this:

<input type="text" @keypress="searchDebounce" />
methods: {
    async search() {
        // get search result
    },
    searchDebounce: _.debounce(async function() {
        await this.search();
        // or you can move everything from search() to here, and delete this.search()
    }, 1000)
}

or even better:

data() {
  return {
    searchDebounce: null
  };
},
created() {
  this.searchDebounce = debounce(this.search, 1000);
}
Owl
  • 6,337
  • 3
  • 16
  • 30