admin管理员组

文章数量:1317915

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)
}

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)
}
Share Improve this question edited Oct 3, 2020 at 17:06 Boussadjra Brahim 1 asked Oct 3, 2020 at 16:28 BlablablaBlablabla 3054 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 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)
}

本文标签: javascriptUse Vuejs 3 with lodash debounce functionStack Overflow