feat:动态路由样式调整

This commit is contained in:
有来技术
2021-11-28 22:49:07 +08:00
parent b048d19d22
commit 1d21c6b098
15 changed files with 146 additions and 150 deletions

View File

@@ -1,43 +1,40 @@
<template>
<component :is="type" v-bind="linkProps(to)">
<a
v-if="isExternal(to)"
:href="to"
target="_blank"
rel="noopener"
>
<slot />
</component>
</a>
<div
v-else
@click="push"
>
<slot />
</div>
</template>
<script>
<script lang="ts">
import { defineComponent } from 'vue'
import { isExternal } from '@/utils/validate'
export default {
import { useRouter } from 'vue-router'
export default defineComponent({
props: {
to: {
type: String,
required: true
}
},
computed: {
isExternal() {
return isExternal(this.to)
},
type() {
if (this.isExternal) {
return 'a'
}
return 'router-link'
setup(props) {
const router = useRouter()
const push = () => {
router.push(props.to)
}
},
methods: {
linkProps(to) {
if (this.isExternal) {
return {
href: to,
target: '_blank',
rel: 'noopener'
}
}
return {
to: to
}
return {
push,
isExternal
}
}
}
</script>
})
</script>