Home >Web Front-end >Vue.js >Who does this in vue point to?
In Vue, the point of this depends on its context: In the root instance: Points to the Vue instance itself. Inside the method: Points to the Vue instance to which the method belongs. Inside the computed property: Points to the Vue instance event handler function to which the getter function belongs. Internal: Points to the DOM element that triggered the event. Internal template: Points to the Vue instance to which the getter function belongs.
this
in Vue points to
In Vue, the this
keyword points to different objects in different places, depending on its context.
Root instance
In the Vue root instance, this
points to the Vue instance itself. This means that you can access all properties and methods of the Vue instance through this
.
Inside the method
Inside the Vue method, this
points to the Vue instance to which the method belongs. This means you can access all properties and methods of the instance via this
.
Inside a computed property
Inside a computed property, this
points to the Vue instance to which the getter function belongs. This means you can access all properties and methods of the instance via this
.
Inside the event handler function
Inside the event handler function, this
points to the DOM element that triggered the event. This means you can access the properties and methods of that DOM element via this
.
Inside the template
Inside the template, this
points to the Vue instance to which the getter function belongs. This means you can access all properties and methods of the instance via this
.
It should be noted that:
this
points to in the parent scope this
, not this
inside the function. bind
or v-on
modifier, this
needs to be explicitly bound, otherwise this
will point to the DOM element. The above is the detailed content of Who does this in vue point to?. For more information, please follow other related articles on the PHP Chinese website!