x-img: revoke blob on unmount

pull/460/head
Varun Patil 2023-02-25 18:20:17 -08:00
parent 87430e298d
commit 0c110ec46e
1 changed files with 11 additions and 0 deletions

View File

@ -38,10 +38,17 @@ export default defineComponent({
this.loadImage(); this.loadImage();
}, },
beforeUnmount() {
this.cleanup();
},
methods: { methods: {
async loadImage() { async loadImage() {
if (!this.src) return; if (!this.src) return;
// Clean up previous blob
this.cleanup();
// Just set src if not http // Just set src if not http
if (this.src.startsWith("data:") || this.src.startsWith("blob:")) { if (this.src.startsWith("data:") || this.src.startsWith("blob:")) {
this.dataSrc = this.src; this.dataSrc = this.src;
@ -61,6 +68,10 @@ export default defineComponent({
if (this.dataSrc === BLANK_IMG) return; if (this.dataSrc === BLANK_IMG) return;
this.$emit("load", this.dataSrc); this.$emit("load", this.dataSrc);
}, },
cleanup() {
if (this.dataSrc.startsWith("blob:")) URL.revokeObjectURL(this.dataSrc);
},
}, },
}); });
</script> </script>