Commit c1d3a9437106d967a62cd822b35cfd5f933fe2d5

Authored by sedice
Committed by GitHub
1 parent 0eb1275c

refactor: 重构button代码props的引入方式,获取更优雅的类型提示 (#2302)

Co-authored-by: zengqinglong <1107238436@qq.com>
src/components/Button/src/BasicButton.vue
... ... @@ -10,14 +10,15 @@
10 10  
11 11 <script lang="ts">
12 12 import { defineComponent } from 'vue';
  13 + import { Button } from 'ant-design-vue';
13 14 export default defineComponent({
14 15 name: 'AButton',
  16 + extends: Button,
15 17 inheritAttrs: false,
16 18 });
17 19 </script>
18 20 <script lang="ts" setup>
19 21 import { computed, unref } from 'vue';
20   - import { Button } from 'ant-design-vue';
21 22 import Icon from '/@/components/Icon/src/Icon.vue';
22 23 import { buttonProps } from './props';
23 24 import { useAttrs } from '/@/hooks/core/useAttrs';
... ...
src/components/Button/src/props.ts
  1 +const validColors = ['error', 'warning', 'success', ''] as const;
  2 +type ButtonColorType = typeof validColors[number];
  3 +
1 4 export const buttonProps = {
2   - color: { type: String, validator: (v) => ['error', 'warning', 'success', ''].includes(v) },
  5 + color: {
  6 + type: String as PropType<ButtonColorType>,
  7 + validator: (v) => validColors.includes(v),
  8 + default: '',
  9 + },
3 10 loading: { type: Boolean },
4 11 disabled: { type: Boolean },
5 12 /**
... ...