index.vue 531 B

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