繁体   English   中英

使用带有 lodash 去抖动功能的 Vue.js 3

[英]Use Vue.js 3 with lodash debounce function

是否有任何解决方案可以在方法上使用 lodash 去抖动? 我还需要在函数中使用“this”。 例子:

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

在 Vue2 中,我可以使用:

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

您的数据属性应该是一个返回对象的函数:

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

并通过为 debounce 回调命名来编写您的方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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