Use Vue.js 3 with lodash debounce function

Viewed 2828

Is there any solution to use lodash debounce on method? I also need 'this' in the function. Example:

data() {
    info: 'Read Me!'
},
methods: {
  readData() {
      console.log(this.info)
  }
}

In Vue2 I could use:

methods: {
  readData: debounce(function() {
      console.log(this.info)
  }, 500)
}
1 Answers

Your data property should be a function that returns an object :

data() {
   return{
    info: 'Read Me!'
   }
},

and write your method by giving a name to the debounce callback :

methods: {
  readData: debounce(function debounceRead() {
      console.log(this.info)
  }, 500)
}
Related