长城汽车软件包管理平台
whychdw
2025-04-26 be81587ef4c7a1711884d7ca8f27cbf85e2d7558
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<template>
  <component :is="linkType" v-bind="linkProps(to)">
    <slot />
  </component>
</template>
 
<script setup lang="ts">
defineOptions({
  name: "AppLink",
  inheritAttrs: false,
});
 
import { isExternal } from "@/utils/index";
 
const props = defineProps({
  to: {
    type: Object,
    required: true,
  },
});
 
const isExternalLink = computed(() => {
  return isExternal(props.to.path || "");
});
 
const linkType = computed(() => (isExternalLink.value ? "a" : "router-link"));
 
const linkProps = (to: any) => {
  if (isExternalLink.value) {
    return {
      href: to.path,
      target: "_blank",
      rel: "noopener noreferrer",
    };
  }
  return { to: to };
};
</script>