RuoYi-Cloud/ruoyi-ui/src/layout/components/Sidebar/Link.vue

44 lines
710 B
Vue
Raw Normal View History

2020-05-24 20:40:55 +08:00
<template>
2020-06-04 16:19:31 +08:00
<component :is="type" v-bind="linkProps(to)">
2020-05-24 20:40:55 +08:00
<slot />
</component>
</template>
<script>
import { isExternal } from '@/utils/validate'
export default {
props: {
to: {
2021-09-08 10:04:23 +08:00
type: [String, Object],
2020-05-24 20:40:55 +08:00
required: true
}
},
2020-06-04 16:19:31 +08:00
computed: {
isExternal() {
return isExternal(this.to)
},
type() {
if (this.isExternal) {
return 'a'
}
return 'router-link'
}
},
2020-05-24 20:40:55 +08:00
methods: {
2020-06-04 16:19:31 +08:00
linkProps(to) {
if (this.isExternal) {
2020-05-24 20:40:55 +08:00
return {
2020-06-04 16:19:31 +08:00
href: to,
2020-05-24 20:40:55 +08:00
target: '_blank',
rel: 'noopener'
}
}
return {
2020-06-04 16:19:31 +08:00
to: to
2020-05-24 20:40:55 +08:00
}
}
}
}
</script>