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

Why are some methods in vue bright and some dark?

下次还敢
Release: 2024-05-08 17:33:16
Original
1102 people have browsed it

The light and dark status of the method in Vue indicates the binding relationship between the method and the Vue instance. The light method is bound to the Vue instance and can access and respond to instance data and changes; the dark method is unbound and cannot access instance data and changes. Methods can be bound via the options API or the template compiler, and unbound in the same way.

Why are some methods in vue bright and some dark?

The reason why the method is bright and dark in Vue

In Vue, the light and dark of the method indicates the binding of the method. fixed state.

The bright method

The bright method means that the method is bound to the Vue instance. This indicates that the method can access the data and methods of the Vue instance and can respond to changes in the Vue instance.

Dark method

Dark method means that the method is not bound to the Vue instance. This indicates that the method cannot access the data and methods of the Vue instance and will not respond to changes in the Vue instance.

Binding method

Methods can be bound in two ways:

  1. By options API: In methods Methods defined in options:
<code class="js">export default {
  methods: {
    myMethod() {
      // ...
    }
  }
}</code>
Copy after login
  1. Via the template compiler: Use the v-on directive in the template :
<code class="html"><button @click="myMethod">...</button></code>
Copy after login

Unbinding method

You can unbind the method in the following ways:

  1. By options API: Remove methods from methods Options:
<code class="js">export default {
  // ...
  methods: {
    // myMethod() { } 已被删除
  }
  // ...
}</code>
Copy after login
  1. Via template compiler: Remove from templates v-on Command:
<code class="html"><button>...</button></code>
Copy after login

The above is the detailed content of Why are some methods in vue bright and some dark?. 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!