Home > Article > Web Front-end > How to bind events to tags in vue
Use the v-on directive in Vue.js to bind label events. The steps are as follows: Select the label to which you want to bind the event. Use the v-on directive to specify the event type and how to handle the event. Specify the Vue method to call in the directive value.
Tag event binding in Vue
In Vue.js, you can pass v-on
Directive binds DOM events to methods in the Vue instance.
Syntax:
<code><标签名 v-on:事件="方法名" other-props="...">...</标签名></code>
Specific steps:
v-on
directive: Use the v-on
directive to specify the event type and method of handling the event. For example, v-on:click
is used to bind click events. v-on
directive. The method name must be a method in the Vue instance. Example:
The following example shows how to bind a click event handler:
<code class="html"><button v-on:click="handleClick">点击我</button></code>
<code class="javascript">// Vue 实例 const app = new Vue({ methods: { handleClick() { console.log("按钮被点击了!"); } } });</code>
When a button is clicked, ## The #handleClick method will be called and output a message to the console.
Note:
), not hyphens form (e.g.
v-on:on-click).
instead of
v-on:onClick.
), you can add a period (.) and modifiers after the event name.
The above is the detailed content of How to bind events to tags in vue. For more information, please follow other related articles on the PHP Chinese website!