Browse Source

fix(table): `reload` in useTable not support await

修复useTable返回的reload方法不支持使用await等待加载完毕的问题
无木 3 years ago
parent
commit
7b6d5e44a9

+ 1 - 0
CHANGELOG.zh_CN.md

@@ -3,6 +3,7 @@
 - **BasicTable**
   - 修复可编辑单元格某些情况下无法提交的问题
   - 修复`inset`属性不起作用的问题
+  - 修复`useTable`与`BasicTable`实例的`reload`方法`await`表现不一致的问题
 - **BasicModal**
   - 修复点击遮罩、按下`Esc`键都不能关闭`Modal`的问题
   - 修复点击关闭按钮、最大化按钮旁边的空白区域也会导致`Modal`关闭的问题

+ 3 - 2
src/components/Table/src/hooks/useDataSource.ts

@@ -275,7 +275,7 @@ export function useDataSource(
           setPagination({
             current: currentTotalPage,
           });
-          fetch(opt);
+          return await fetch(opt);
         }
       }
 
@@ -295,6 +295,7 @@ export function useDataSource(
         items: unref(resultItems),
         total: resultTotal,
       });
+      return resultItems;
     } catch (error) {
       emit('fetch-error', error);
       dataSourceRef.value = [];
@@ -319,7 +320,7 @@ export function useDataSource(
   }
 
   async function reload(opt?: FetchParams) {
-    await fetch(opt);
+    return await fetch(opt);
   }
 
   onMounted(() => {

+ 1 - 1
src/components/Table/src/hooks/useTable.ts

@@ -68,7 +68,7 @@ export function useTable(tableProps?: Props): [
     getForm: () => FormActionType;
   } = {
     reload: async (opt?: FetchParams) => {
-      getTableInstance().reload(opt);
+      return await getTableInstance().reload(opt);
     },
     setProps: (props: Partial<BasicTableProps>) => {
       getTableInstance().setProps(props);