x-img: revoke blob on unmount
parent
87430e298d
commit
0c110ec46e
|
@ -38,10 +38,17 @@ export default defineComponent({
|
|||
this.loadImage();
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.cleanup();
|
||||
},
|
||||
|
||||
methods: {
|
||||
async loadImage() {
|
||||
if (!this.src) return;
|
||||
|
||||
// Clean up previous blob
|
||||
this.cleanup();
|
||||
|
||||
// Just set src if not http
|
||||
if (this.src.startsWith("data:") || this.src.startsWith("blob:")) {
|
||||
this.dataSrc = this.src;
|
||||
|
@ -61,6 +68,10 @@ export default defineComponent({
|
|||
if (this.dataSrc === BLANK_IMG) return;
|
||||
this.$emit("load", this.dataSrc);
|
||||
},
|
||||
|
||||
cleanup() {
|
||||
if (this.dataSrc.startsWith("blob:")) URL.revokeObjectURL(this.dataSrc);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue