Skip to content

Commit

Permalink
perf: 优化平台logo获取方式
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Oct 21, 2023
1 parent af224dc commit 1462411
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/layout/components/sidebar/horizontal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const {
logout,
backTopMenu,
onPanel,
getLogo,
username,
userAvatar,
avatarsStyle,
Expand All @@ -43,7 +44,7 @@ nextTick(() => {
class="horizontal-header"
>
<div class="horizontal-header-left" @click="backTopMenu">
<img src="/logo.svg" alt="logo" />
<img :src="getLogo()" alt="logo" />
<span>{{ title }}</span>
</div>
<el-menu
Expand Down
6 changes: 3 additions & 3 deletions src/layout/components/sidebar/logo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const props = defineProps({
collapse: Boolean
});
const { title } = useNav();
const { title, getLogo } = useNav();
</script>

<template>
Expand All @@ -19,7 +19,7 @@ const { title } = useNav();
class="sidebar-logo-link"
:to="getTopMenu()?.path ?? '/'"
>
<img src="/logo.svg" alt="logo" />
<img :src="getLogo()" alt="logo" />
<span class="sidebar-title">{{ title }}</span>
</router-link>
<router-link
Expand All @@ -29,7 +29,7 @@ const { title } = useNav();
class="sidebar-logo-link"
:to="getTopMenu()?.path ?? '/'"
>
<img src="/logo.svg" alt="logo" />
<img :src="getLogo()" alt="logo" />
<span class="sidebar-title">{{ title }}</span>
</router-link>
</transition>
Expand Down
6 changes: 6 additions & 0 deletions src/layout/hooks/useNav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ export function useNav() {
return remainingPaths.includes(path);
}

/** 获取`logo` */
function getLogo() {
return new URL("/logo.svg", import.meta.url).href;
}

return {
title,
device,
Expand All @@ -139,6 +144,7 @@ export function useNav() {
menuSelect,
handleResize,
resolvePath,
getLogo,
isCollapse,
pureApp,
username,
Expand Down
4 changes: 3 additions & 1 deletion src/views/components/animatecss/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ defineOptions({
const icon = ref("");
watch(icon, () => console.log("icon", icon.value));
watch(icon, () => {
console.log("icon", icon.value);
});
</script>

<template>
Expand Down

1 comment on commit 1462411

@xiaoxian521
Copy link
Member Author

@xiaoxian521 xiaoxian521 commented on 1462411 Oct 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里调整logo获取方式主要原因如下:
在升级vite5 beta后,发现打包会报如下信息,所以进行了修复

image

当然还有一个好处是,如果用的logo不是svg格式,只需要改这里一处即可

Please sign in to comment.