Commit 9f5085c9f9f46b09391156b17091c1771bc13026

Authored by 无木
1 parent 9f4d1719

fix(table): useTable support onChange

修复useTable无法直接通过设置onChange来注册change事件响应的问题
src/components/Table/src/BasicTable.vue
... ... @@ -58,6 +58,7 @@
58 58  
59 59 import { omit } from 'lodash-es';
60 60 import { basicProps } from './props';
  61 + import { isFunction } from '/@/utils/is';
61 62  
62 63 export default defineComponent({
63 64 components: {
... ... @@ -142,6 +143,9 @@
142 143 function handleTableChange(...args) {
143 144 onTableChange.call(undefined, ...args);
144 145 emit('change', ...args);
  146 + // 解决通过useTable注册onChange时不起作用的问题
  147 + const { onChange } = unref(getProps);
  148 + onChange && isFunction(onChange) && onChange.call(undefined, ...args);
145 149 }
146 150  
147 151 const {
... ...
src/views/demo/table/UseTable.vue
... ... @@ -15,7 +15,7 @@
15 15 <a-button class="mr-2" @click="clearSelect"> 清空选中行 </a-button>
16 16 <a-button class="mr-2" @click="getPagination"> 获取分页信息 </a-button>
17 17 </div>
18   - <BasicTable @register="registerTable" @change="onChange" />
  18 + <BasicTable @register="registerTable" />
19 19 </div>
20 20 </template>
21 21 <script lang="ts">
... ... @@ -54,6 +54,7 @@
54 54 columns: getBasicColumns(),
55 55 rowKey: 'id',
56 56 showTableSetting: true,
  57 + onChange,
57 58 rowSelection: {
58 59 type: 'checkbox',
59 60 },
... ...