如何等待异步去抖功能?

问题描述 投票:0回答:0

我正在尝试等待异步去抖动 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,
      }),
    };
  }
vue.js asynchronous async-await vuejs3 debouncing
© www.soinside.com 2019 - 2024. All rights reserved.