Skip to content

Commit af55511

Browse files
committed
fix(table): table columns setting error
1 parent aa596af commit af55511

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

CHANGELOG.zh_CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- 新增`mixSideTrigger`配置。用于配置左侧混合模式菜单打开方式。可选`hover`,默认`click`
66

7+
### 🐛 Bug Fixes
8+
9+
- 修复表格列配置已知问题
10+
711
## 2.0.0-rc.15 (2020-12-31)
812

913
### ✨ 表格破坏性更新

src/components/Table/src/hooks/useColumns.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BasicColumn, BasicTableProps, CellFormat, GetColumnsParams } from '../types/table';
22
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';
44
import { isBoolean, isArray, isString, isObject } from '/@/utils/is';
55
import { DEFAULT_ALIGN, PAGE_SIZE, INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG } from '../const';
66
import { useI18n } from '/@/hooks/web/useI18n';
@@ -156,11 +156,22 @@ export function useColumns(
156156
return viewColumns;
157157
});
158158

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+
// });
164175

165176
/**
166177
* set columns

src/components/Table/src/hooks/useTable.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import type { PaginationProps } from '../types/pagination';
33
import type { DynamicProps } from '/@/types/utils';
44
import { getDynamicProps } from '/@/utils';
55

6-
import { ref, onUnmounted, unref } from 'vue';
6+
import { ref, onUnmounted, unref, watch } from 'vue';
77
import { isProdMode } from '/@/utils/env';
88
import { isInSetup } from '/@/utils/helper/vueHelper';
99
import { error } from '/@/utils/log';
10-
import { watchEffect } from 'vue';
1110
import type { FormActionType } from '/@/components/Form';
1211

1312
type Props = Partial<DynamicProps<BasicTableProps>>;
@@ -33,12 +32,18 @@ export function useTable(
3332
}
3433
tableRef.value = instance;
3534
formRef.value = formInstance;
36-
// tableProps && instance.setProps(tableProps);
35+
tableProps && instance.setProps(getDynamicProps(tableProps));
3736
loadedRef.value = true;
3837

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+
);
4247
}
4348

4449
function getTableInstance(): TableActionType {

0 commit comments

Comments
 (0)