简体   繁体   中英

Use Vue.js 3 with lodash debounce function

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM