[Vuejs]-Why to reference the this variable to modify the DOM elements? :Clarification on 'this' in Vue Component

-1👍

Look closely at the Lifecycle-Diagram in official docs. You’re trying to run this.methodName1() in created which is hooked before your methods, meaning you’re trying to run a method that has not been attached yet.
mounted is where all your methods are already available.
Change:

created: function () {
     this.methodName1()
},

to

mounted: function () {
     this.methodName1()
},

and you should be good to go.

Leave a comment