XTextButton.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script lang="ts" name="XTextButton" setup>
  2. import { propTypes } from '@/utils/propTypes'
  3. import { PropType } from 'vue'
  4. const props = defineProps({
  5. modelValue: propTypes.bool.def(false),
  6. loading: propTypes.bool.def(false),
  7. preIcon: propTypes.string.def(''),
  8. postIcon: propTypes.string.def(''),
  9. title: propTypes.string.def(''),
  10. type: propTypes.oneOf(['', 'primary', 'success', 'warning', 'danger', 'info']).def('primary'),
  11. circle: propTypes.bool.def(false),
  12. round: propTypes.bool.def(false),
  13. plain: propTypes.bool.def(false),
  14. onClick: { type: Function as PropType<(...args) => any>, default: null }
  15. })
  16. const getBindValue = computed(() => {
  17. const delArr: string[] = ['title', 'preIcon', 'postIcon', 'onClick']
  18. const attrs = useAttrs()
  19. const obj = { ...attrs, ...props }
  20. for (const key in obj) {
  21. if (delArr.indexOf(key) !== -1) {
  22. delete obj[key]
  23. }
  24. }
  25. return obj
  26. })
  27. </script>
  28. <template>
  29. <el-button link v-bind="getBindValue" @click="onClick">
  30. <Icon v-if="preIcon" :icon="preIcon" class="mr-1px" />
  31. {{ title ? title : '' }}
  32. <Icon v-if="postIcon" :icon="postIcon" class="mr-1px" />
  33. </el-button>
  34. </template>
  35. <style lang="scss" scoped>
  36. :deep(.el-button.is-text) {
  37. margin-left: 0;
  38. padding: 8px 4px;
  39. }
  40. :deep(.el-button.is-link) {
  41. margin-left: 0;
  42. padding: 8px 4px;
  43. }
  44. </style>