x-img: revoke blob on unmount
parent
87430e298d
commit
0c110ec46e
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue