Commit be2d11d5d344a508e94abe3534726c80e1f1f271
Committed by
GitHub
1 parent
88451565
fix: Fix the invalid hot update of BasicButton when changing style outside (#1016)
* chore: ignore bak dir Signed-off-by: LiLi <urfreespace@gmail.com> * fix: 修复BasicButton在外部改变样式热更新无效问题 Signed-off-by: LiLi <urfreespace@gmail.com> * chore: remove extra ignore Signed-off-by: LiLi <urfreespace@gmail.com> * chore: ignore fix Signed-off-by: LiLi <urfreespace@gmail.com>
Showing
2 changed files
with
8 additions
and
6 deletions
src/components/Button/src/BasicButton.vue
... | ... | @@ -8,18 +8,20 @@ |
8 | 8 | </Button> |
9 | 9 | </template> |
10 | 10 | <script lang="ts"> |
11 | - import { defineComponent, computed } from 'vue'; | |
11 | + import { defineComponent, computed, unref } from 'vue'; | |
12 | 12 | import { Button } from 'ant-design-vue'; |
13 | 13 | import Icon from '/@/components/Icon/src/Icon.vue'; |
14 | 14 | import { buttonProps } from './props'; |
15 | + import { useAttrs } from '/@/hooks/core/useAttrs'; | |
15 | 16 | |
16 | 17 | export default defineComponent({ |
17 | 18 | name: 'AButton', |
18 | 19 | components: { Button, Icon }, |
19 | 20 | inheritAttrs: false, |
20 | 21 | props: buttonProps, |
21 | - setup(props, { attrs }) { | |
22 | + setup(props) { | |
22 | 23 | // get component class |
24 | + const attrs = useAttrs({ excludeDefaultKeys: false }); | |
23 | 25 | const getButtonClass = computed(() => { |
24 | 26 | const { color, disabled } = props; |
25 | 27 | return [ |
... | ... | @@ -27,12 +29,11 @@ |
27 | 29 | [`ant-btn-${color}`]: !!color, |
28 | 30 | [`is-disabled`]: disabled, |
29 | 31 | }, |
30 | - attrs.class, | |
31 | 32 | ]; |
32 | 33 | }); |
33 | 34 | |
34 | 35 | // get inherit binding value |
35 | - const getBindValue = computed(() => ({ ...attrs, ...props })); | |
36 | + const getBindValue = computed(() => ({ ...unref(attrs), ...props })); | |
36 | 37 | |
37 | 38 | return { getBindValue, getButtonClass }; |
38 | 39 | }, | ... | ... |
src/hooks/core/useAttrs.ts
... | ... | @@ -3,6 +3,7 @@ import type { Ref } from 'vue'; |
3 | 3 | interface Params { |
4 | 4 | excludeListeners?: boolean; |
5 | 5 | excludeKeys?: string[]; |
6 | + excludeDefaultKeys?: boolean; | |
6 | 7 | } |
7 | 8 | |
8 | 9 | const DEFAULT_EXCLUDE_KEYS = ['class', 'style']; |
... | ... | @@ -16,9 +17,9 @@ export function useAttrs(params: Params = {}): Ref<Recordable> | {} { |
16 | 17 | const instance = getCurrentInstance(); |
17 | 18 | if (!instance) return {}; |
18 | 19 | |
19 | - const { excludeListeners = false, excludeKeys = [] } = params; | |
20 | + const { excludeListeners = false, excludeKeys = [], excludeDefaultKeys = true } = params; | |
20 | 21 | const attrs = shallowRef({}); |
21 | - const allExcludeKeys = excludeKeys.concat(DEFAULT_EXCLUDE_KEYS); | |
22 | + const allExcludeKeys = excludeKeys.concat(excludeDefaultKeys ? DEFAULT_EXCLUDE_KEYS : []); | |
22 | 23 | |
23 | 24 | // Since attrs are not reactive, make it reactive instead of doing in `onUpdated` hook for better performance |
24 | 25 | instance.attrs = reactive(instance.attrs); | ... | ... |