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[]) => {
|
||||
const images = paths.map((path) => {
|
||||
if (imageCache.has(path)) {
|
||||
return imageCache.get(path)!;
|
||||
}
|
||||
|
||||
const img = document.createElement("img");
|
||||
img.src = path;
|
||||
return img;
|
||||
});
|
||||
imageCache.set(path, img);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
images.forEach((img) => {
|
||||
img.src = "";
|
||||
img.remove();
|
||||
});
|
||||
return img;
|
||||
});
|
||||
|
||||
return images;
|
||||
|
||||
Reference in New Issue
Block a user