简体   繁体   中英

How do i define this method in vue.js?

I am attempting to create a JavaScript Text Animation but i am getting particleArray is undefined i am not sure how to resolve the issue i have tried moving the code from the mounted method since it would load before being defined but same results.

export default {
    data : function (){

         return {
             particleArray: null,
             x:null,
             y:null,
             radius: 150,
             vuedata: null,
        }

    },
class Particle{
           constructor(x, y){
              this.x = x + 100;
              this.y = y;
              this.size = 3;
              this.baseX = this.x;
              this.baseY = this.y;
              this.density = (Math.random() *30) + 1;
        }


           draw(){
                ctx.fillStyle = '#fff';
                ctx.beginPath();
                ctx.ard(this.x, this.y, this.size,0,Math.PI * 2);
                ctx.closePath();
                ctx.fill();

           }
       }

        function init(){
            this.particleArray = [];
            particleArray.push(new Particle(50,50));
        }

The answer is this.particleArray.push(new Particle(50,50));

this.particleArray = []; assigns the data property particleArray the value [] .

particleArray.push(new Particle(50,50)); attempts a method on a local variable that does not exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM