Newer
Older
DH_Apicture / src / layout / components / Sidebar / Link.vue
@zhangqy zhangqy on 29 Nov 592 bytes first commit
  1. <template>
  2. <component :is="type" v-bind="linkProps()">
  3. <slot />
  4. </component>
  5. </template>
  6.  
  7. <script setup>
  8. import { isExternal } from '@/utils/validate'
  9.  
  10. const props = defineProps({
  11. to: {
  12. type: [String, Object],
  13. required: true
  14. }
  15. })
  16.  
  17. const isExt = computed(() => {
  18. return isExternal(props.to)
  19. })
  20.  
  21. const type = computed(() => {
  22. if (isExt.value) {
  23. return 'a'
  24. }
  25. return 'router-link'
  26. })
  27.  
  28. function linkProps() {
  29. if (isExt.value) {
  30. return {
  31. href: props.to,
  32. target: '_blank',
  33. rel: 'noopener'
  34. }
  35. }
  36. return {
  37. to: props.to
  38. }
  39. }
  40. </script>