feat: 侧边动态路由菜单支持参数

This commit is contained in:
郝先瑞
2024-05-24 18:17:01 +08:00
parent 1c4326fdfa
commit c5f7e4b081
4 changed files with 39 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
<template>
<component :is="type" v-bind="linkProps(to)">
<component :is="linkType" v-bind="linkProps(to)">
<slot></slot>
</component>
</template>
@@ -14,20 +14,25 @@ import { isExternal } from "@/utils/index";
const props = defineProps({
to: {
type: String,
type: Object,
required: true,
},
});
const isExternalLink = computed(() => isExternal(props.to));
const type = computed(() => {
return isExternalLink.value ? "a" : "router-link";
const isExternalLink = computed(() => {
return isExternal(props.to.path || "");
});
const linkProps = (to: string) => {
return isExternalLink.value
? { href: to, target: "_blank", rel: "noopener noreferrer" }
: { to };
const linkType = computed(() => (isExternalLink.value ? "a" : "router-link"));
const linkProps = (to: any) => {
if (isExternalLink.value) {
return {
href: to.path,
target: "_blank",
rel: "noopener noreferrer",
};
}
return { to: to };
};
</script>