index.vue 613 B

1234567891011121314151617181920212223242526272829303132333435
  1. <template>
  2. <component :is="type" v-bind="linkProps()">
  3. <slot />
  4. </component>
  5. </template>
  6. <script lang="ts" setup>
  7. import { isExternal } from '/@/utils/validate'
  8. defineOptions({
  9. name: 'VabLink',
  10. })
  11. const props = defineProps({
  12. to: {
  13. type: String,
  14. required: true,
  15. },
  16. target: {
  17. type: String,
  18. default: '',
  19. },
  20. })
  21. const type = computed(() => (isExternal(props.to) ? 'a' : 'router-link'))
  22. const linkProps = () =>
  23. isExternal(props.to)
  24. ? {
  25. href: props.to,
  26. target: '_blank',
  27. rel: 'noopener',
  28. }
  29. : { to: props.to, target: props.target }
  30. </script>