Vue去抖动的方法?
我知道 Vue.js 具有内置的功能,可以对输入字段进行去抖动.我创建了一个滑块,它触发了一个不使用输入字段的方法,我想知道我是否可以利用方法内部的去抖动功能.
I know Vue.js has functionality built in to debounce on an input field. I have created a slider that fires a method that does not use an input field though, and I was wondering if I can take advantage of the debounce functionality inside of a method.
除了简单地向输入添加去抖动之外,甚至可以使用此功能吗?还是我需要为此编写自己的功能?
Is it even possible to use this functionality outside of simply adding a debounce to an input? Or do I need to write my own functionality for this?
我刚刚尝试过这样做,但它似乎不起作用:
I've just tried doing something like this but it does not seem to work:
this.$options.filters.debounce(this.search(), 2000);
推荐答案
对于任何想知道如何做到这一点的人.我通过使用我发现的一个很棒的小片段来解决这个问题:
For anyone who is wondering on how to do this. I fixed this by using an awesome little snippet I found:
我的数据中的属性
timer: 0
去抖动功能
// clears the timer on a call so there is always x seconds in between calls
clearTimeout(this.timer);
// if the timer resets before it hits 150ms it will not run
this.timer = setTimeout(function(){
this.search()
}.bind(this), 150);
相关文章