vue中使用Lodash 的debounce,一定要放在created里才能生效吗?

https://cn.vuejs.org/v2/guide...
把this.debouncedGetAnswer = _.debounce(this.getAnswer, 500)
改成debouncedGetAnswer:function(){_.debounce(this.getAnswer, 500)}放在methods里就无效。

阅读 4.6k
2 个回答

使用方法不正确

debouncedGetAnswer:_.debounce(function(){
    this.getAnswer()
}, 500)

需要预先执行一次,

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题