Methods and Events
{% from 'components/codeblock.macro.html' import codeblock %}
Methods usually refer to invoking the methods of a component through the component element's ID to perform some actions. For example, spz-lightbox is not displayed on the page by default. When we want it to be displayed, we need to call its open method to open it.
Events usually refer to the automatic triggering of events by a component after completing some operations. We can listen to these events to execute other logic after some actions are completed. For instance, after spz-lightbox is opened, we can listen to the @open event to call the component's methods or global methods to implement some logic.
Key Takeaways First
@tap,@open, etc. map an event to an action/method via a small DSL.- The 3 most common patterns are: show/hide, toggle class, and scroll to an element.
- If an action does not work, check: the target
idexists, the method name is valid, and the expression is complete (for example,hello.hide).
The 3 Most Common Examples
1) Tap to hide/show
2) Tap to toggle a class
3) Tap to scroll to an element
Usage
@eventName is usually used to listen to an element's event handlers. The supported events depend on the element.
The syntax value is a simple domain-specific language, in the form of:
For explanations of each part of the syntax, please refer to the table below.
One Event Handling Multiple Methods
Use a semicolon (;) to separate each method and execute multiple methods in sequence for the same event.
Globally Defined Events and Methods
Lessjs defines a global tap event that you can listen to on any HTML element (including Lessjs elements or native HTML elements).
Lessjs also defines global show, hide, scrollTo, and toggleClass methods that you can trigger on any HTML element.
Element-specific Events
*-All Elements
Input Elements
Element-specific Methods
*(All Elements)
Global Methods
Global methods are mounted on SPZ and invoked using the SPZ.methodName form.
AI Usage Notes (LLM Ready)
- Section density: detected 7 level-2 headings.
- Example density: detected 2 code blocks.
- Read conclusions first: extract definitions, constraints, and boundary conditions.
- Then verify with examples: rely on executable snippets rather than prose only.
- Finally cross-check: open related component pages to avoid doc/runtime drift.