🔒 Properly deregisters event listener on destroy

This commit is contained in:
Alicia Sykes 2021-12-27 01:04:35 +00:00
parent 76ea9e0cee
commit 051ed1841c
1 changed files with 2 additions and 9 deletions

View File

@ -35,13 +35,8 @@ export default {
this.initiate();
},
beforeDestroy() {
if (this.eventListener) {
window.removeEventListener(this.eventListener);
}
window.removeEventListener('load', this.injectHtml);
},
data: () => ({
eventListener: null,
}),
methods: {
/* Injects users content */
injectHtml() {
@ -70,9 +65,7 @@ export default {
if (document.readyState === 'complete' || document.readyState === 'loaded') {
this.injectHtml();
} else {
this.eventListener = window.addEventListener('load', () => {
this.injectHtml();
});
window.addEventListener('load', this.injectHtml);
}
},
update() {