新增
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<template>
|
||||
<component :is="type" v-bind="linkProps">
|
||||
<slot />
|
||||
</component>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* @description 兼容第三方页面的跳转
|
||||
*/
|
||||
import { isExternal } from '@/utils/validate'
|
||||
|
||||
interface Props {
|
||||
to: string | Record<string, string>
|
||||
replace?: boolean
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const isExternalLink = computed(() => {
|
||||
return typeof props.to !== 'object' && isExternal(props.to)
|
||||
})
|
||||
|
||||
const type = computed(() => {
|
||||
if (isExternalLink.value) {
|
||||
return 'a'
|
||||
}
|
||||
return 'router-link'
|
||||
})
|
||||
|
||||
const linkProps = computed(() => {
|
||||
if (isExternalLink.value) {
|
||||
return {
|
||||
href: props.to,
|
||||
target: '_blank'
|
||||
}
|
||||
}
|
||||
return props
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user