我似乎不能去掉(lodash)计算属性或vuex getter。去抖动的函数总是返回未定义的。
https://jsfiddle.net/guanzo/yqk0jp1j/2/
HTML:
<div id="app">
<input v-model="text">
<div>computed: {{ textComputed }} </div>
<div>debounced: {{ textDebounced }} </div>
</div>JS:
new Vue({
el:'#app',
data:{
text:''
},
computed:{
textDebounced: _.debounce(function(){
return this.text
},500),
textComputed(){
return this.text
}
}
})发布于 2017-06-27 13:23:58
我不明白为什么去反跳函数在计算属性上不起作用。但是,另一种解决方案是将去抖动放在methods部分中的函数上,并通过watch调用它。
https://jsfiddle.net/vsc4npv3/
HTML:
<div id="app">
<input v-model="text">
<div>computed: {{ textComputed }} </div>
<div>debounced: {{ debouncedText }} </div>
</div>JavaScript:
var x = new Vue({
el:'#app',
data:{
text:'',
debouncedText: ''
},
watch: {
text: function (val) {
this.debouncer();
}
},
computed:{
textComputed(){
return this.text;
}
},
methods: {
debouncer: _.debounce(function(){
this.debouncedText = this.text;
},500)
}
})https://stackoverflow.com/questions/44772629
复制相似问题