fix(assets): cache in useImage
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
|
const imageCache = new Map<string, HTMLImageElement>();
|
||||||
|
|
||||||
export const useImages = (...paths: string[]) => {
|
export const useImages = (...paths: string[]) => {
|
||||||
const images = paths.map((path) => {
|
const images = paths.map((path) => {
|
||||||
|
if (imageCache.has(path)) {
|
||||||
|
return imageCache.get(path)!;
|
||||||
|
}
|
||||||
|
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
img.src = path;
|
img.src = path;
|
||||||
return img;
|
imageCache.set(path, img);
|
||||||
});
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
return img;
|
||||||
images.forEach((img) => {
|
|
||||||
img.src = "";
|
|
||||||
img.remove();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return images;
|
return images;
|
||||||
|
|||||||
Reference in New Issue
Block a user