Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  41] [ 3]  / answers: 1 / hits: 16535  / 9 Years ago, mon, september 7, 2015, 12:00:00

I am trying to use the the debounce filter as per the Vue.js docs so I can prevent firing an Ajax function while the user is typing into an input. In the past, I have used setTimeout to manually prevent sending the request after each letter is entered and to use a resetting delay, but I would like to do it the Vue.js way.



Here is what I tried:



<input
v-model=myInput
v-on=keyup: someAjaxFunction | debounce 500
>


No examples are given in the docs specifically for this filter. Am I even putting the filter in the right place?




debounce



this filter only works with v-on



this filter takes one optional argument



Wrap the handler to debounce it for X milliseconds, where X
is the argument. Default is 300ms. A debounced handler will be delayed
until at least X ms has passed after the call moment; if the handler
is called again before the delay period, the delay poriod is reset to
X ms.




I have also tried this: ( because the docs mention Wrap the handler... )



<input
v-model=myInput
v-on=keyup: debounce( someAjaxFunction, 500 )
>


I could really use an example.


More From » vue.js

 Answers
11

Your first example is correct:



<input v-model=myInput v-on=keyup: someAjaxFunction | debounce 500>


With Vue.js 1.0.0-beta.x, the new syntax is:



<input v-model=myInput on-keyup=someAjaxFunction | debounce 500>

[#65157] Friday, September 4, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
levidaylonj

Total Points: 392
Total Questions: 100
Total Answers: 112

Location: Bahrain
Member since Fri, Sep 16, 2022
2 Years ago
;