Handling user interactions is a fundamental part of any Web Component. The `on()` method provides a straightforward way to listen for and respond to DOM events.
Written By Joel
Last updated About 1 month ago
Using on()
The on()
method receives an event name and a handler function. The handler receives an enhanced event object that includes both the native event properties and a reference to the requery-js element via event.element
:
defineComponent("my-component", {
setup(component, props, store) {
component.query("button").on("click", (evt) => {
// evt: native event properties
// evt.element: requery-js element reference
});
}
})
Could not load article.
Could not load article.