Link.vue 567 Bytes
Newer Older
Pan's avatar
Pan committed
1 2

<template>
Pan's avatar
Pan committed
3
  <!-- eslint-disable vue/require-component-is -->
Pan's avatar
Pan committed
4
  <component v-bind="linkProps(to)">
花裤衩's avatar
花裤衩 committed
5
    <slot />
Pan's avatar
Pan committed
6 7 8 9
  </component>
</template>

<script>
Pan's avatar
Pan committed
10
import { isExternal } from '@/utils/validate'
Pan's avatar
Pan committed
11 12 13 14 15 16 17 18 19 20

export default {
  props: {
    to: {
      type: String,
      required: true
    }
  },
  methods: {
    linkProps(url) {
Pan's avatar
Pan committed
21
      if (isExternal(url)) {
Pan's avatar
Pan committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
        return {
          is: 'a',
          href: url,
          target: '_blank',
          rel: 'noopener'
        }
      }
      return {
        is: 'router-link',
        to: url
      }
    }
  }
}
</script>