Aura components in Salesforce
Aura Components
Aura components are the self-contained and reusable units of an app. They represent a reusable section of the UI, and can range in granularity from a single line of text to an entire app.
The framework includes a set of prebuilt components. For example, components that come with the Lightning Design System styling are available in the lightning namespace. These components are also known as the base Lightning components. You can assemble and configure components to form new components in an app. Components are rendered to produce HTML DOM elements within the browser.
A component can contain other components, as well as HTML, CSS, JavaScript, or any other Web-enabled code. This enables you to build apps with sophisticated UIs.
The details of a component's implementation are encapsulated. This allows the consumer of a component to focus on building their app, while the component author can innovate and make changes without breaking consumers. You configure components by setting the named attributes that they expose in their definition. Components interact with their environment by listening to or publishing events.
Here's an example of a simple Aura component
Aura Component
<aura:component controller="AccountController">
<aura:attribute name="accounts" type="List" />
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<ul>
<aura:iteration items="{!v.accounts}" var="acc">
<li>{!acc.Name}</li>
</aura:iteration>
</ul>
</aura:component>
Apex Controller
public with sharing class AccountController {
@AuraEnabled
public static List<Account> getAccounts() {
return [SELECT Id, Name FROM Account LIMIT 10];
}
}
Javascript Controller
({
init : function(component, event, helper) {
var action = component.get("c.getAccounts");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.accounts", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Technology Stack:
Aura components are built using the Aura framework, which is a client-side JavaScript framework developed by Salesforce.
Aura components use a combination of HTML, JavaScript, and Aura markup language (similar to XML) to define the user interface and logic.
References
Comments
Post a Comment