Merge pull request #39 from cshaptx4869/patch-11

refactor(SidebarMenuItemTitle): ♻️ 去除冗余代码
This commit is contained in:
Ray Hao
2024-03-01 13:02:28 +08:00
committed by GitHub

View File

@@ -1,17 +1,15 @@
<template>
<el-icon v-if="icon && icon.startsWith('el-icon')" class="sub-el-icon">
<component :is="renderIcon(icon.replace('el-icon-', ''))" />
<component :is="icon.replace('el-icon-', '')" />
</el-icon>
<SvgIcon v-else-if="icon" :icon-class="icon" />
<SvgIcon v-else icon-class="menu" />
<svg-icon v-else-if="icon" :icon-class="icon" />
<svg-icon v-else icon-class="menu" />
<span v-if="title" class="ml-1">{{ translateRouteTitle(title) }}</span>
</template>
<script setup lang="ts">
import { translateRouteTitle } from "@/utils/i18n";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
defineProps({
icon: {
type: String,
@@ -22,18 +20,6 @@ defineProps({
default: "",
},
});
/**
* 渲染图标组件
*/
type IconNames = keyof typeof ElementPlusIconsVue;
const renderIcon = (iconName: string) => {
const iconComponent = ElementPlusIconsVue[iconName as IconNames];
if (iconComponent) {
return h(resolveComponent(iconComponent.name));
}
return null;
};
</script>
<style lang="scss" scoped>