相关疑难解决方法(0)

lodash debounce不能在匿名函数中工作

您好我无法弄清楚为什么当直接传递给keyup事件时debounce函数按预期工作; 但如果我将它包装在匿名函数中,它就不起作用.

我有问题:http : //jsfiddle.net/6hg95/1/

编辑:添加了我尝试过的所有东西.

HTML

<input id='anonFunction'/>
<input id='noReturnAnonFunction'/>
<input id='exeDebouncedFunc'/>
<input id='function'/>
<div id='output'></div>
Run Code Online (Sandbox Code Playgroud)

JAVASCRIPT

$(document).ready(function(){
    $('#anonFunction').on('keyup', function () {
        return _.debounce(debounceIt, 500, false); //Why does this differ from #function
    });
    $('#noReturnAnonFunction').on('keyup', function () {
        _.debounce(debounceIt, 500, false); //Not being executed
    });
    $('#exeDebouncedFunc').on('keyup', function () {
        _.debounce(debounceIt, 500, false)(); //Executing the debounced function results in wrong behaviour
    });
    $('#function').on('keyup', _.debounce(debounceIt, 500, false)); //This is working.
});

function debounceIt(){
    $('#output').append('debounced');
}
Run Code Online (Sandbox Code Playgroud)

anonFunction并且noReturnAnonFunction不会启动去抖功能; 但是最后一次function …

javascript jquery lodash

52
推荐指数
4
解决办法
5万
查看次数

如何在异步功能上使用反跳功能?

如何debounceasync功能上使用?我的vue-app中有一个方法,该方法可从API检索数据,该方法连续调用该API,而我想避免这种情况。

这是我的方法:

methods: {
    async getAlbums () {
     const response = await AlbumService.fetchAlbums()
     this.albums = response.data.albums
    } 
}
Run Code Online (Sandbox Code Playgroud)

我以前已经安装了,lodash那么如何实现呢?

javascript debouncing vue.js vuejs2 debounce

1
推荐指数
1
解决办法
5502
查看次数

标签 统计

javascript ×2

debounce ×1

debouncing ×1

jquery ×1

lodash ×1

vue.js ×1

vuejs2 ×1