我正在尝试等待异步去抖动 API 调用。但是等待不起作用。它立即记录
'Awaited'
。我做错了什么?
我的 onMounted 设置:
import debounce from 'lodash/debounce';
onMounted(async () => {
console.log('Awaiting');
const fetchAbsentiesAsync = await apiCallConst();
await Promise.all([fetchAbsentiesAsync]);
console.log('Awaited');
isLoading.value = false;
});
我的 API 调用:
const apiCallConst = debounce(async () => {
await ApiService.makeApiCall()
.then((data) => {
state.data = data;
})
}, 10000);
ApiService.makeApiCall:
async makeApiCall(): Promise<string> {
return {
data: await apiFetch(`group/data`, {
method: HttpMethods.POST,
}),
};
}