Blame view

HHECS.Web/src/layout/components/Sidebar/Link.vue 671 Bytes
胡菁 authored
1
2
3
4
5
6
7
<template>
  <component :is="type" v-bind="linkProps(to)">
    <slot />
  </component>
</template>

<script>
胡菁 authored
8
import { isExternal } from "@/utils/validate";
胡菁 authored
9
10
11
12
13

export default {
  props: {
    to: {
      type: String,
胡菁 authored
14
15
      required: true,
    },
胡菁 authored
16
17
18
  },
  computed: {
    isExternal() {
胡菁 authored
19
      return isExternal(this.to);
胡菁 authored
20
21
22
    },
    type() {
      if (this.isExternal) {
胡菁 authored
23
        return "a";
胡菁 authored
24
      }
胡菁 authored
25
26
      return "router-link";
    },
胡菁 authored
27
28
29
30
31
32
  },
  methods: {
    linkProps(to) {
      if (this.isExternal) {
        return {
          href: to,
胡菁 authored
33
34
35
          target: "_blank",
          rel: "noopener",
        };
胡菁 authored
36
37
      }
      return {
胡菁 authored
38
39
40
41
42
        to: to,
      };
    },
  },
};
胡菁 authored
43
</script>