I'm learning Vue and I want to bind multipe events to a single function in the same element, something like the following (in plain JavaScript, feel free to run the code snippet):
let mainElement = document.querySelector("h1");
// I made an 'events' array to loop
["click", "mouseenter", "And we can keep adding events..."]
.forEach( event => {
mainElement.addEventListener(event, myFunction);
}
);
function myFunction() {
// DO SOMETHING, for example:
mainElement.style.color = "red";
}
const resetButton = document
.querySelector("button")
.addEventListener("click", () => {
mainElement.style.color = "black";
});
<h1 style="color: black">This is the element we want to control</h1>
<button>Reset</button>
In Vue.js I can bind ONE SINGLE EVENT directly to an element like this:
<h1 @mouseenter="myFunction">This is the element we want to control</h1>
I want to know if there is a way to bind MULTIPLE EVENTS to a single function inside the same element, does anyone know if there is a syntax like this?
<h1 @[mouseenter,click,mouseleave...]="myFunction">This is the element we want to control</h1>