Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript中以间隔获取数据?_Javascript_Vue.js_Pusher_Pusher Js - Fatal编程技术网

在javascript中以间隔获取数据?

在javascript中以间隔获取数据?,javascript,vue.js,pusher,pusher-js,Javascript,Vue.js,Pusher,Pusher Js,我对Pusher有以下代码: Echo.private("channel").listen(".foobar", (e) => { this.fetchData(); }); 当有传入请求时,我希望再次获取数据。但不是在每一个推动者事件上。我希望数据在5秒内只提取一次 我在考虑当有新的传入事件时重置间隔,但如何实现这一点?好的,首先它是一个Laravel Echo代码。它可能在幕后使用pusher,但说它是pusher代码有点不正确 那么,如

我对Pusher有以下代码:

Echo.private("channel").listen(".foobar", (e) => {
   this.fetchData();
});
当有传入请求时,我希望再次获取数据。但不是在每一个推动者事件上。我希望数据在5秒内只提取一次


我在考虑当有新的传入事件时重置间隔,但如何实现这一点?

好的,首先它是一个
Laravel Echo
代码。它可能在幕后使用pusher,但说它是pusher代码有点不正确

那么,如果我没弄错的话,你需要某种去盎司功能。例如
lodash

const debouncedFunction=u.debounce(()=>{
this.fetchData()
}, 5000);
Echo.private('channel')。listen('.foobar',e=>{
脱口而出
})
debounce
将创建函数的去抖动版本,然后您可以调用该函数,甚至可以取消该函数,因为它带有
cancel
方法

debouncedFunction.cancel()