38 lines
576 B
Vue
38 lines
576 B
Vue
![]() |
<template>
|
||
|
<component :is="linkProps.is" v-bind="linkProps.props">
|
||
|
<slot />
|
||
|
</component>
|
||
|
</template>
|
||
|
|
||
|
<script setup>
|
||
|
import { computed } from 'vue'
|
||
|
import { isExternal } from '@/utils/validate'
|
||
|
|
||
|
const props = defineProps({
|
||
|
to: {
|
||
|
type: String,
|
||
|
required: true
|
||
|
}
|
||
|
})
|
||
|
|
||
|
const linkProps = computed(() => {
|
||
|
if (isExternal(props.to)) {
|
||
|
return {
|
||
|
is: 'a',
|
||
|
props: {
|
||
|
href: props.to,
|
||
|
target: '_blank',
|
||
|
rel: 'noopener'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
is: 'router-link',
|
||
|
props: {
|
||
|
to: props.to
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
</script>
|