Reputation: 3
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));
}
Upvotes: 0
Views: 47
Reputation: 2411
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.
Upvotes: 1