useElTableData.ts 767 B

1234567891011121314151617181920212223242526
  1. import { nextTick, Ref } from 'vue';
  2. /**
  3. * 获取 El-Table的数据并处理total和loading
  4. * @param apiFunction 请求的接口函数
  5. * @param query 请求参数
  6. * @param tableData El-Table的数据
  7. * @param total El-Table数据的总条数
  8. * @param loading El-Table的loading状态
  9. */
  10. export async function useElTableData(apiFunction: Function, query: any, tableData: Ref, total: Ref, loading: Ref) {
  11. loading.value = true;
  12. try {
  13. const response = await apiFunction(query);
  14. total.value = response.total;
  15. tableData.value = response.data;
  16. } catch (error) {
  17. console.log('error=>', error);
  18. } finally {
  19. loading.value = false;
  20. await nextTick();
  21. // 触发窗口 resize 事件
  22. window.dispatchEvent(new Event('resize'));
  23. }
  24. }