Browse Source

资源加载方式修改

JXDS18FUJT 2 năm trước cách đây
mục cha
commit
0834096931
1 tập tin đã thay đổi với 11 bổ sung8 xóa
  1. 11 8
      src/utils/utils.ts

+ 11 - 8
src/utils/utils.ts

@@ -1,9 +1,12 @@
 // 获取assets静态资源
-const getAssetsFile = (url: string) => {
-    return new URL(`../assets/images/${url}`, import.meta.url).href;
-  };
-   
-  export default {getAssetsFile:getAssetsFile}
-    
-  
- 
+const getAssetsFile = (name: string) => {
+  if (typeof name === 'undefined') return 'error.png'
+  const path = `/src/assets/images/${name}`
+  const modules = import.meta.globEager('/src/assets/images/*')
+  return modules[path]?.default
+
+};
+
+export default { getAssetsFile: getAssetsFile }
+
+