8

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 Answer 1

7

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)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.