[Vuejs]-How to bind click events to elements with a specific class

0👍

You just have to pass your method on the v-on:click function defined on your HTML tag. See:

<button v-on:click="sendMessage()" value='Send'>Send Message</button>
methods: {
        sendMessage(e) {
            console.log(`Hello, world from the button ${e.target.value}`)
        },
},

mounted: {
        this.sendMessage()
}

Where e is the event dispatched when you click the button.

-1👍

I’ll do this the old fashioned way.

Using Jquery (or native JS)

$(document).on('click', 'yourCssClass', function(e){
    yourJsCode;
});

Leave a comment