vp-api-function.vue 872 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <script setup lang="ts">
  2. import { computed } from 'vue'
  3. import ApiTyping from './vp-api-typing.vue'
  4. import type { PropType } from 'vue'
  5. type ParamType = [string, string]
  6. const props = defineProps({
  7. /**
  8. * @description params list, shape of Array<[key: string, value: string]>
  9. */
  10. params: {
  11. type: Array as PropType<Array<ParamType>>,
  12. default: () => [],
  13. },
  14. returns: {
  15. type: String,
  16. default: 'void',
  17. },
  18. })
  19. const mappedParams = computed(() =>
  20. props.params
  21. .reduce((params, [key, val]) => {
  22. let type = val
  23. if (Array.isArray(val)) {
  24. type = val.join(' | ')
  25. }
  26. return params.concat([`${key}: ${type}`])
  27. }, [] as string[])
  28. .join(', ')
  29. )
  30. const details = computed(() => `(${mappedParams.value}) => ${props.returns}`)
  31. </script>
  32. <template>
  33. <api-typing type="Function" :details="details" />
  34. </template>