Skip to content

Commit e152cc1

Browse files
committed
revoke unused object urls
1 parent b508327 commit e152cc1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/components/FileItem.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, ref, watchEffect } from 'vue';
2+
import { computed, ref, watchEffect, watch, onUnmounted } from 'vue';
33
import type { FileObj } from '@/types/file';
44
import { useI18n } from '@/hooks/useI18n';
55
@@ -23,8 +23,12 @@ watchEffect(() => {
2323
2424
const objectUrl = computed(() => URL.createObjectURL(props.fileObj.file));
2525
26+
watch(objectUrl, (_, oldUrl) => URL.revokeObjectURL(oldUrl));
27+
2628
const computeFileSize = (size: number) =>
2729
(size / (1024 * 1024)).toLocaleString(undefined, { minimumFractionDigits: 1, maximumFractionDigits: 1 }); // NoSonar this is to convert byte to MB
30+
31+
onUnmounted(() => URL.revokeObjectURL(objectUrl.value));
2832
</script>
2933

3034
<template>

0 commit comments

Comments
 (0)