Home >Web Front-end >Vue.js >What does vm in vue mean?
vm in Vue is a local variable that refers to the current Vue instance and provides ways to access instance properties and methods such as data, computed properties, methods, and life cycle hooks. 1. vm.someData: Access data in the template. 2. this.someData: Access data in component code. 3. this.someComputed: Access computed properties. 4. this.someMethod: Call the method.
#What is vm in Vue?
vm in Vue.js is a local variable that refers to the Vue instance. In other words, vm is an object pointing to the current Vue instance.
The structure of a Vue instance
A Vue instance is an object that contains the following properties and methods:
Purpose of vm
vm provides a way to access Vue instances in templates and code. It can be used to access data, computed properties, methods and lifecycle hooks.
How to use vm
In the Vue template, you can use the following syntax to access vm:
<code class="html">this.someData</code>
In the Vue component code, you can use the following syntax Access vm:
<code class="js">this.someData</code>
Example
The following example shows how to use vm to access data, computed properties and methods:
<code class="js">const app = new Vue({ data() { return { count: 0 } }, computed: { doubleCount() { return this.count * 2 } }, methods: { incrementCount() { this.count++ } } }) app.vm.doubleCount // 0 app.vm.incrementCount() app.vm.doubleCount // 2</code>
The above is the detailed content of What does vm in vue mean?. For more information, please follow other related articles on the PHP Chinese website!