gpt4 book ai didi

javascript - 在 Axios 请求上使用 Lodash 的 Debounce 会产生意外结果

转载 作者:行者123 更新时间:2023-12-03 13:51:29 26 4
gpt4 key购买 nike

每次输入文本时,我的应用程序都会更新。然后对 axios 请求使用 debounce,请求会排队,直到计时器用完,然后它们会立即全部发出。我试图将请求限制为每 10 秒一次。我哪里出错了?

如果这很重要的话,我会在 ReactJS 中这样做。

const debouncedSync = _.debounce(() => {this.sync () }, 10000);

sync = (requestBody) => {
axios.post('http://127.0.0.1:8000/Server/', requestBody);
};

最佳答案

请检查faxios debounce

let fetcher = faxios()
.baseURL('http://jsonplaceholder.typicode.com')
.url('posts', 1, 'comments')
.debounce(1 * 1000); // debounce time 1000ms

fetcher
.FETCH // => Promise
.then(res => console.log('res1:',res))
.catch(err => console.log('error1:', err));

fetcher
.FETCH // => Promise
.then(res => console.log('res2:', res))
.catch(err => console.log('error2:', err));

fetcher
.FETCH // => Promise
.then(res => console.log('res3:',res))
.catch(err => console.log('error3:', err));

fetcher
.FETCH // => Promise
.then(res => console.log('res4:', res))
.catch(err => console.log('error4:', err));


/**

error1:debounced

error2:debounced

error3:debounced

res4:{...}

**/

关于javascript - 在 Axios 请求上使用 Lodash 的 Debounce 会产生意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39809844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com