Vue: Proper use of debounce property

Created on 8 Jul 2015  路  6Comments  路  Source: vuejs/vue

Is debounce supposed to throttle the keyup event on a text input? If so I'm having trouble getting this to work. Debounce works fine throttling the model update, but the keyup event still fires as soon as a key is released. I'm not sure if this is supposed to work this way or not. Thanks!

Most helpful comment

The docs could use some improvement. The debounce property does not debounce any DOM events, it only debounces model updates. Since you are already using v-model, you should think in terms of "reacting to model changes" rather than "reacting to DOM events". So, use a watcher to watch the change of the bound value:

<input v-model="someValue" debounce="500">
data: {
  someValue: ''
},
watch: {
  someValue: function (value) {
    // this callback is debounced
  }
}

And please use vuejs/Discussion for questions - this repo's issue tracker is for bugs and features only.

All 6 comments

The docs could use some improvement. The debounce property does not debounce any DOM events, it only debounces model updates. Since you are already using v-model, you should think in terms of "reacting to model changes" rather than "reacting to DOM events". So, use a watcher to watch the change of the bound value:

<input v-model="someValue" debounce="500">
data: {
  someValue: ''
},
watch: {
  someValue: function (value) {
    // this callback is debounced
  }
}

And please use vuejs/Discussion for questions - this repo's issue tracker is for bugs and features only.

@yyx990803 Is this still the case? I tried doing this and the debounce didn't apply.

http://vuejs.org/v2/guide/migration.html#debounce-Param-Attribute-for-v-model-removed

@sirlancelot thanks

Since debounce is removed
Docs should be updated here as well https://012.vuejs.org/guide/forms.html#Input_Debounce

@deepaksisodiya If you look at the URL you pasted, you'll notice it's 012.vuejs.org. That is the documentation for a pre-release version of Vue.js. The latest version can be found here: https://vuejs.org/v2/api/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

franciscolourenco picture franciscolourenco  路  3Comments

aviggngyv picture aviggngyv  路  3Comments

Jokcy picture Jokcy  路  3Comments

fergaldoyle picture fergaldoyle  路  3Comments

paceband picture paceband  路  3Comments