javascriptvue.jsvuetify.jsparticles.js

Integrate ParticlesJs into a view component


I want to integrate ParticlesJs into my landing page. So only my home view should use this particles configuration and render particles.

I created a snippet and added the ParticlesJs dependencies

https://codesandbox.io/s/ol2rnrlxxq

Two problems come up:

The final result should look like this.

enter image description here

I added the flat attribute to the card so fixing the two problems should make it work.


Solution

  • You have to put your particlesJS initialize code in mounted hook instead of created. Because in created hook, DOM elements does not created yet. Please see more about mounted.

    export default {
      mounted () {
        particlesJS("particles-js", {
          ...
        })
      }
    }
    

    To make particles-js fullscreen:

    #particles-js {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: pink;
    }
    

    To make your layout center (from Layout grid system example):

    <v-layout align-center justify-center row fill-height/>
    

    codesandbox.io