You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
656 B
44 lines
656 B
3 years ago
|
<template>
|
||
|
<component :is="type" v-bind="linkProps(to)">
|
||
|
<slot/>
|
||
|
</component>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import { isExternal } from '@/utils/validate'
|
||
|
|
||
|
export default {
|
||
|
props: {
|
||
|
to: {
|
||
|
type: String,
|
||
|
required: true
|
||
|
}
|
||
|
},
|
||
|
computed: {
|
||
|
isExternal() {
|
||
|
return isExternal(this.to)
|
||
|
},
|
||
|
type() {
|
||
|
if (this.isExternal) {
|
||
|
return 'a'
|
||
|
}
|
||
|
return 'router-link'
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
linkProps(to) {
|
||
|
if (this.isExternal) {
|
||
|
return {
|
||
|
href: to,
|
||
|
target: '_blank',
|
||
|
rel: 'noopener'
|
||
|
}
|
||
|
}
|
||
|
return {
|
||
|
to: to
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|