我有一個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