Vue.JS event handling tutorial and code examples

藏色散人
Release: 2019-04-01 09:52:17
Original
2342 people have browsed it

In this article we will introduce to you event processing in vuejs.

Vuejs provides us with a directive calledv:on, which can help us register and listen fordomevents, so that whenever the event is triggered, The method passed to the event will be called.

v:onSyntax of the directive

 
Copy after login

In the above code, we listen for ## on the button #clickevent so that whenever the user clicks on the button, it calls thehandleClickmethod.

 
Copy after login

How to pass parameters to event handlers?

Sometimes event handler methods can also accept parameters.

 
Copy after login

Here, we create an

incrementmethod with only one parameter value to pass the parameters to theincrement(10)method.

How to access the default event object?

To access the default event object in the method vuejs, you need to provide a variable named $event.

 
Copy after login

Here, we access the event object by using the special $event variable provided by Vuejs.

Sometimes we need to access event objects and parameters at the same time.

 
Copy after login

Shorthand syntax

vuejs also provides a shorthand syntax to listen to

domevents.

   
Copy after login
This article is an introduction to Vue.JS event processing. I hope it will be helpful to friends in need!

The above is the detailed content of Vue.JS event handling tutorial and code examples. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
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!