我在keyUp上调用searchkeyword函数。我想在快速键入新字母时取消/ clearTimeout $ emit,以便只调用几次$ emit。但是控制台会在每次搜索关键字调用时被调用/反跳。
methods: {
searchKeyword : function() {
var scope = this;
(this.debounce(function(){
scope.$emit("search-keyword", scope.keyword);
console.log("Called");
},350))();
},
debounce: function (func, delay) {
var timeout;
return function() {
const context = this;
const args = arguments;
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(context, args), delay);
}
}
}
相关分类