Directives
In Regor, directives are special attributes that start with the “r-” prefix. They allow you to enhance the behavior and appearance of your applications. Below, you’ll find a list of supported directives categorized by their functionality.
Note: The directive prefix “r-” can be customized using
RegorConfig.getDefault().setDirectives('v-')to align with a different naming convention, such as Vue’s “v-” prefix.
Binding Directives:
r-bindBinds an element’s attribute to a component’s data, allowing dynamic updates.r-modelEnables two-way data binding between form inputs.r-textSets the element’s text content to the result of an expression.r-htmlRenders the result of an expression as HTML content within the element.r-onAttaches event listeners to the element and invokes specified component methods.r-showConditionally displays the element based on the truthiness of an expression.
Control Flow Directives:
r-forRenders a set of elements based on an array and a template.r-ifConditionally renders the element based on the truthiness of an expression.r-elseProvides an alternative rendering when used in conjunction withr-if.r-else-ifConditionally renders the element as an alternative tor-if.
Utility Directives:
r-preExcludes HTML element from Regor bindings.:classBinds one or more class names to an element based on expressions.:styleBinds one or more inline styles to an element based on expressions.:refProvides a reference to an element in the template, allowing you to interact with it programmatically.:keyProvides a unique identifier for each item in a list, aiding efficient updates and rendering.:isSpecifies the component to dynamically render based on a value or expression.r-teleport: Teleports the element to anywhere in the DOM. Unlike Vue, teleport is a directive to avoid component overhead.:propsVue usesv-bindfor component property passing. However, this can conflict withv-bind’s attribute fall-through logic. Hence, Regor defines a dedicated directive to pass properties using object syntax. It enables passing properties without defining them in the component’s props contract.:props-onceSimilar to:propsbut it doesn’t observe the entire reactive tree of the template expression. Tail reactivity still works.
Event Handling Directives:
@Shorthand forr-onto bind event listeners.
Attribute Binding Directives:
These directives empower you to create dynamic and interactive user interfaces, enhancing the user experience of your Regor-powered applications. Click on each directive to view its detailed documentation, including examples and usage guidelines.