11<template >
2- <div :id =" id" ></div >
2+ <div :id =" id" ></div >
33</template >
44
55<script setup lang="ts">
@@ -11,66 +11,66 @@ export type IParticlesProps = ISourceOptions;
1111let container: Container | undefined , engine: Engine | undefined ;
1212
1313const props = defineProps <{
14- id: string ;
15- options? : IParticlesProps ;
16- url? : string ;
17- theme? : string ;
14+ id: string ;
15+ options? : IParticlesProps ;
16+ url? : string ;
17+ theme? : string ;
1818}>();
1919
2020const emit = defineEmits <{
21- (e : " particlesLoaded" , container ? : Container ): void ;
21+ (e : " particlesLoaded" , container ? : Container ): void ;
2222}>();
2323
2424const initEventHandler = (e : Event ) => {
25- const evt = e as CustomEvent <Engine >;
25+ const evt = e as CustomEvent <Engine >;
2626
27- engine = evt .detail ;
27+ engine = evt .detail ;
2828
29- loadParticles ();
29+ loadParticles ();
3030};
3131
3232addEventListener (" particlesInit" , initEventHandler );
3333
3434const loadParticles = async () => {
35- if (! engine ) {
36- engine = tsParticles ;
37- }
35+ if (! engine ) {
36+ engine = tsParticles ;
37+ }
3838
39- container = await engine .load ({
40- id: props .id ,
41- url: props .url ,
42- options: props .options ,
43- });
39+ container = await engine .load ({
40+ id: props .id ,
41+ url: props .url ,
42+ options: props .options ,
43+ });
4444
45- emit (" particlesLoaded" , container );
45+ emit (" particlesLoaded" , container );
4646};
4747
4848onMounted (() => {
49- nextTick (() => {
50- if (! props .id ) {
51- throw new Error (" Prop 'id' is required!" );
52- }
49+ nextTick (() => {
50+ if (! props .id ) {
51+ throw new Error (" Prop 'id' is required!" );
52+ }
5353
54- loadParticles ();
55- });
54+ loadParticles ();
55+ });
5656});
5757
5858onUnmounted (() => {
59- if (! container ) {
60- return ;
61- }
59+ if (! container ) {
60+ return ;
61+ }
6262
63- container .destroy ();
63+ container .destroy ();
6464
65- container = undefined ;
65+ container = undefined ;
6666
67- removeEventListener (" particlesInit" , initEventHandler );
67+ removeEventListener (" particlesInit" , initEventHandler );
6868});
6969
7070watch (
7171 () => props .theme ,
7272 () => {
73- container ?.loadTheme (props .theme );
73+ container ?.loadTheme (props .theme );
7474 },
7575 { immediate: true , deep: true },
7676);
0 commit comments