我有一个Vue公司的模板简单的输入框,我想或多或少地使用反跳这样的:如何在Vue2中实现去抖动?
<input type="text" v-model="filterKey" debounce="500">
然而debounce
物业已经deprecated in Vue 2。该建议只说:“使用v-on:输入+第三方去抖功能”。
你如何正确实施它?
我试图实现它使用lodash,V系列:输入和V型,但我想知道是否有可能没有额外的变量做。
模板:
<input type="text" v-on:input="debounceInput" v-model="searchInput">
在脚本:
data: function() {
return {
searchInput: '',
filterKey: ''
}
},
methods: {
debounceInput: _.debounce(function() {
this.filterKey = this.searchInput;
}, 500)
}
的filterkey然后在computed
道具以后使用。
试试这个HTTP:// stackoverflow.com/questions/41230343/how-to-temporize-the-analysis-of-an-input-field/41232221#41232221 – sobolevn
我建议仔细阅读:https://vuejs.org/v2/guide/migration .html#debounce -Param-Attribute-for-v-model-removed –
有一个e xample在指南中:https://vuejs.org/v2/guide/computed.html#Watchers – Bengt