Skip to content

Commit cc3bf7e

Browse files
committed
fix: action绑定
1 parent cf27fd8 commit cc3bf7e

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

apps/web-antd/src/components/table-action/table-action.vue

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { PropType } from 'vue';
44
55
import type { ActionItem, PopConfirm } from './typing';
66
7-
import { computed, unref } from 'vue';
7+
import { computed, unref, watch } from 'vue';
88
99
import { useAccess } from '@vben/access';
1010
import { IconifyIcon } from '@vben/icons';
@@ -60,21 +60,20 @@ function isIfShow(action: ActionItem): boolean {
6060
6161
/** 处理按钮 actions */
6262
const getActions = computed(() => {
63-
return (props.actions || []).filter((action: ActionItem) => isIfShow(action));
63+
const actions = props.actions || [];
64+
return actions.filter((action: ActionItem) => isIfShow(action));
6465
});
6566
6667
/** 处理下拉菜单 actions */
6768
const getDropdownList = computed(() => {
68-
return (props.dropDownActions || []).filter((action: ActionItem) =>
69-
isIfShow(action),
70-
);
69+
const dropDownActions = props.dropDownActions || [];
70+
return dropDownActions.filter((action: ActionItem) => isIfShow(action));
7171
});
7272
7373
/** Space 组件的 size */
7474
const spaceSize = computed(() => {
75-
return unref(getActions)?.some((item: ActionItem) => item.type === 'link')
76-
? 0
77-
: 8;
75+
const actions = unref(getActions);
76+
return actions?.some((item: ActionItem) => item.type === 'link') ? 0 : 8;
7877
});
7978
8079
/** 获取 PopConfirm 属性 */
@@ -137,6 +136,15 @@ function handleButtonClick(action: ActionItem) {
137136
action.onClick();
138137
}
139138
}
139+
140+
// 监听props变化,强制重新计算
141+
watch(
142+
() => [props.actions, props.dropDownActions],
143+
() => {
144+
// 这里不需要额外处理,computed会自动重新计算
145+
},
146+
{ deep: true },
147+
);
140148
</script>
141149

142150
<template>

0 commit comments

Comments
 (0)