Commit af55511bd6e533ab68356aa9038f80f50f53cf26

Authored by vben
1 parent aa596af6

fix(table): table columns setting error

CHANGELOG.zh_CN.md
@@ -4,6 +4,10 @@ @@ -4,6 +4,10 @@
4 4
5 - 新增`mixSideTrigger`配置。用于配置左侧混合模式菜单打开方式。可选`hover`,默认`click` 5 - 新增`mixSideTrigger`配置。用于配置左侧混合模式菜单打开方式。可选`hover`,默认`click`
6 6
  7 +### 🐛 Bug Fixes
  8 +
  9 +- 修复表格列配置已知问题
  10 +
7 ## 2.0.0-rc.15 (2020-12-31) 11 ## 2.0.0-rc.15 (2020-12-31)
8 12
9 ### ✨ 表格破坏性更新 13 ### ✨ 表格破坏性更新
src/components/Table/src/hooks/useColumns.ts
1 import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table'; 1 import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table';
2 import type { PaginationProps } from '../types/pagination'; 2 import type { PaginationProps } from '../types/pagination';
3 -import { unref, ComputedRef, Ref, computed, watchEffect, ref, toRaw } from 'vue'; 3 +import { unref, ComputedRef, Ref, computed, watch, ref, toRaw } from 'vue';
4 import { isBoolean, isArray, isString, isObject } from '/@/utils/is'; 4 import { isBoolean, isArray, isString, isObject } from '/@/utils/is';
5 import { DEFAULT_ALIGN, PAGE_SIZE, INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG } from '../const'; 5 import { DEFAULT_ALIGN, PAGE_SIZE, INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG } from '../const';
6 import { useI18n } from '/@/hooks/web/useI18n'; 6 import { useI18n } from '/@/hooks/web/useI18n';
@@ -156,11 +156,22 @@ export function useColumns( @@ -156,11 +156,22 @@ export function useColumns(
156 return viewColumns; 156 return viewColumns;
157 }); 157 });
158 158
159 - watchEffect(() => {  
160 - const columns = toRaw(unref(propsRef).columns);  
161 - columnsRef.value = columns;  
162 - cacheColumns = columns?.filter((item) => !item.flag) ?? [];  
163 - }); 159 + watch(
  160 + () => unref(propsRef).columns,
  161 + (columns) => {
  162 + columnsRef.value = columns;
  163 + cacheColumns = columns?.filter((item) => !item.flag) ?? [];
  164 + }
  165 + );
  166 +
  167 + // watchEffect(() => {
  168 + // const columns = toRaw(unref(propsRef).columns);
  169 + // console.log('======================');
  170 + // console.log(111);
  171 + // console.log('======================');
  172 + // columnsRef.value = columns;
  173 + // cacheColumns = columns?.filter((item) => !item.flag) ?? [];
  174 + // });
164 175
165 /** 176 /**
166 * set columns 177 * set columns
src/components/Table/src/hooks/useTable.ts
@@ -3,11 +3,10 @@ import type { PaginationProps } from '../types/pagination'; @@ -3,11 +3,10 @@ import type { PaginationProps } from '../types/pagination';
3 import type { DynamicProps } from '/@/types/utils'; 3 import type { DynamicProps } from '/@/types/utils';
4 import { getDynamicProps } from '/@/utils'; 4 import { getDynamicProps } from '/@/utils';
5 5
6 -import { ref, onUnmounted, unref } from 'vue'; 6 +import { ref, onUnmounted, unref, watch } from 'vue';
7 import { isProdMode } from '/@/utils/env'; 7 import { isProdMode } from '/@/utils/env';
8 import { isInSetup } from '/@/utils/helper/vueHelper'; 8 import { isInSetup } from '/@/utils/helper/vueHelper';
9 import { error } from '/@/utils/log'; 9 import { error } from '/@/utils/log';
10 -import { watchEffect } from 'vue';  
11 import type { FormActionType } from '/@/components/Form'; 10 import type { FormActionType } from '/@/components/Form';
12 11
13 type Props = Partial<DynamicProps<BasicTableProps>>; 12 type Props = Partial<DynamicProps<BasicTableProps>>;
@@ -33,12 +32,18 @@ export function useTable( @@ -33,12 +32,18 @@ export function useTable(
33 } 32 }
34 tableRef.value = instance; 33 tableRef.value = instance;
35 formRef.value = formInstance; 34 formRef.value = formInstance;
36 - // tableProps && instance.setProps(tableProps); 35 + tableProps && instance.setProps(getDynamicProps(tableProps));
37 loadedRef.value = true; 36 loadedRef.value = true;
38 37
39 - watchEffect(() => {  
40 - tableProps && instance.setProps(getDynamicProps(tableProps));  
41 - }); 38 + watch(
  39 + () => tableProps,
  40 + () => {
  41 + tableProps && instance.setProps(getDynamicProps(tableProps));
  42 + },
  43 + {
  44 + immediate: true,
  45 + }
  46 + );
42 } 47 }
43 48
44 function getTableInstance(): TableActionType { 49 function getTableInstance(): TableActionType {