我在keyUp上調(diào)用searchkeyword函數(shù)。我想在快速鍵入新字母時(shí)取消/ clearTimeout $ emit,以便只調(diào)用幾次$ emit。但是控制臺(tái)會(huì)在每次搜索關(guān)鍵字調(diào)用時(shí)被調(diào)用/反跳。 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); } } }
每次都會(huì)調(diào)用去抖功能
縹緲止盈
2021-05-10 01:09:05