diff --git a/src/views/home.vue b/src/views/home.vue index 9ad8256..5e5ca41 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -10,6 +10,16 @@ import { storeToRefs } from 'pinia' import { filterMenu, getRoutePath } from "@/utils/menuUtils.js"; import SettingsIcon from '@/assets/blue.png'; +// 使用import.meta.glob导入所有SVG图标 +const icons = import.meta.glob('@/assets/SvgIcons/*.svg', { eager: true, import: 'default' }) + +// 创建获取图标路径的函数 +const getIconPath = (menuName) => { + // 为菜单名添加.svg扩展名并在icons对象中查找 + const iconKey = `@/assets/SvgIcons/${menuName}.svg`; + return icons[iconKey] || ''; // 如果找不到,返回空字符串 +} + // ----------------------------------- @@ -87,7 +97,6 @@ function findBestMatch(menuList, path) { return bestMatch || path // fallback 到当前路径 } -// 获取菜单图标(require动态导入) @@ -156,7 +165,7 @@ function logout() {