BasicButton.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <template>
  2. <Button v-bind="getBindValue" :class="getButtonClass" @click="onClick">
  3. <template #default="data">
  4. <Icon :icon="preIcon" v-if="preIcon" :size="iconSize" />
  5. <slot v-bind="data || {}"></slot>
  6. <Icon :icon="postIcon" v-if="postIcon" :size="iconSize" />
  7. </template>
  8. </Button>
  9. </template>
  10. <script lang="ts">
  11. export default {
  12. name: 'AButton',
  13. inheritAttrs: false,
  14. };
  15. </script>
  16. <script lang="ts" setup>
  17. import { computed, unref } from 'vue';
  18. import { Button } from 'ant-design-vue';
  19. import Icon from '/@/components/Icon/src/Icon.vue';
  20. import { buttonProps } from './props';
  21. import { useAttrs } from '/@/hooks/core/useAttrs';
  22. const props = defineProps(buttonProps);
  23. // get component class
  24. const attrs = useAttrs({ excludeDefaultKeys: false });
  25. const getButtonClass = computed(() => {
  26. const { color, disabled } = props;
  27. return [
  28. {
  29. [`ant-btn-${color}`]: !!color,
  30. [`is-disabled`]: disabled,
  31. },
  32. ];
  33. });
  34. // get inherit binding value
  35. const getBindValue = computed(() => ({ ...unref(attrs), ...props }));
  36. </script>