Home > Web Front-end > Vue.js > body text

What does vm in vue mean?

下次还敢
Release: 2024-05-09 16:21:17
Original
478 people have browsed it

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 does vm in vue mean?

#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:

  • data : Reactive object containing instance data
  • computed : Function containing calculated properties
  • methods : Function containing methods
  • watch: Observer that monitors data attribute changes
  • lifecycle hooks: Hook function executed during the instance life cycle

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>
Copy after login

In the Vue component code, you can use the following syntax Access vm:

<code class="js">this.someData</code>
Copy after login

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>
Copy after login

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!

Related labels:
vue
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!