DEV Community

Discussion on: Hands-on Vue.js for Beginners (Part 2)

Collapse
 
aniketnaik321 profile image
aniketnaik321

Is it possible in Vue.js to put event handling code just in one place(in js file), like we do in jquery.

$("#btnSubmit").click(function(e){
alert("example");
});

Collapse
 
marinamosti profile image
Marina Mosti

Hi Aniketnaik, well... In Vue as you probably know by now, we declare the listeners directly on the template using @click or @event and pass in the name of a method. It is possible to attach listeners using vanilla javascript by doing element.addEventListener and passing a function, but it depends on what you're trying to accomplish. Good luck