Skip to content

Commit 8ca5ebb

Browse files
authored
Merge pull request #68 from Alhada06/main
fix: Remove particleInit event listening when a component is unmounted
2 parents 8150718 + c90d66f commit 8ca5ebb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

components/vue3/src/components/vue-particles.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ const emit = defineEmits<{
2121
(e: "particlesLoaded", container?: Container): void;
2222
}>();
2323
24-
addEventListener("particlesInit", (e: Event) => {
24+
const initEventHandler = (e: Event) => {
2525
const evt = e as CustomEvent<Engine>;
2626
2727
engine = evt.detail;
2828
2929
loadParticles();
30-
});
30+
};
31+
addEventListener("particlesInit", initEventHandler);
3132
3233
const loadParticles = async () => {
3334
if (!engine) {
@@ -57,9 +58,9 @@ onUnmounted(() => {
5758
if (!container) {
5859
return;
5960
}
60-
6161
container.destroy();
6262
container = undefined;
63+
removeEventListener("particlesInit", initEventHandler);
6364
});
6465
6566
watch(

0 commit comments

Comments
 (0)