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,6 +58,7 @@
58 58
59 import { omit } from 'lodash-es'; 59 import { omit } from 'lodash-es';
60 import { basicProps } from './props'; 60 import { basicProps } from './props';
  61 + import { isFunction } from '/@/utils/is';
61 62
62 export default defineComponent({ 63 export default defineComponent({
63 components: { 64 components: {
@@ -142,6 +143,9 @@ @@ -142,6 +143,9 @@
142 function handleTableChange(...args) { 143 function handleTableChange(...args) {
143 onTableChange.call(undefined, ...args); 144 onTableChange.call(undefined, ...args);
144 emit('change', ...args); 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 const { 151 const {
src/views/demo/table/UseTable.vue
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 <a-button class="mr-2" @click="clearSelect"> 清空选中行 </a-button> 15 <a-button class="mr-2" @click="clearSelect"> 清空选中行 </a-button>
16 <a-button class="mr-2" @click="getPagination"> 获取分页信息 </a-button> 16 <a-button class="mr-2" @click="getPagination"> 获取分页信息 </a-button>
17 </div> 17 </div>
18 - <BasicTable @register="registerTable" @change="onChange" /> 18 + <BasicTable @register="registerTable" />
19 </div> 19 </div>
20 </template> 20 </template>
21 <script lang="ts"> 21 <script lang="ts">
@@ -54,6 +54,7 @@ @@ -54,6 +54,7 @@
54 columns: getBasicColumns(), 54 columns: getBasicColumns(),
55 rowKey: 'id', 55 rowKey: 'id',
56 showTableSetting: true, 56 showTableSetting: true,
  57 + onChange,
57 rowSelection: { 58 rowSelection: {
58 type: 'checkbox', 59 type: 'checkbox',
59 }, 60 },