我该如何使用debounce
on an async
功能?我内部有一个方法vue
-app 从一个 API 接收数据,该 API 不断调用我想避免的 API。
这是我的方法:
methods: {
async getAlbums () {
const response = await AlbumService.fetchAlbums()
this.albums = response.data.albums
}
}
我已经安装了lodash
以前那么我怎样才能实现这一目标呢?
洛达什的debouncefunction 接受一个 function 、等待时间并返回一个函数。
所以这样做:
methods: {
getAlbums: _.debounce(async function() {
const response = await AlbumService.fetchAlbums();
this.albums = response.data.albums;
}, 1000);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)