Home > Article > Web Front-end > Why are some methods in vue bright and some dark?
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.
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:
methods
Methods defined in options: <code class="js">export default { methods: { myMethod() { // ... } } }</code>
v-on
directive in the template :<code class="html"><button @click="myMethod">...</button></code>
Unbinding method
You can unbind the method in the following ways:
methods
Options: <code class="js">export default { // ... methods: { // myMethod() { } 已被删除 } // ... }</code>
v-on
Command: <code class="html"><button>...</button></code>
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!