Hello All,
Today we are going to understadn ,howe we can use/Access Lightning Aura component in to Visualforce page.we need to know because some of customer using Visualforce as per thire requirement .Sometimes there is a requirement to use lightning component in visualforce page.
Lightning Components for Visualforce is based on Lightning Out, a powerful and flexible feature that lets you embed Lightning components into almost any web page.
basic example of the lightning component and then display lightning component in the visualforce page.
Lightning Component LightVFExample
1
2
3
4
5
| < aura:component > < div > < h2 > This is lightning component with in visualforce page</ h2 > </ div > </ aura:component > |
Lightning App LightVFExampleApp
Here important point is that ltng:outApp needs to be extended in app.
ltng:outApp adds SLDS resources to the page to allow our Lightning components to be styled with the Salesforce Lightning Design System. If we don’t want SLDS resources added to the page, we need to extend from ltng:outAppUnstyled instead.
1
2
3
| < aura:application extends = "ltng:outApp" access = "GLOBAL" > < aura:dependency resource = "c:LightVFExample" /> </ aura:application > |
Visualforce page LightningExampleVF
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| < apex:page showHeader = "false" sidebar = "false" > < apex:includeLightning /> < apex:includeScript value = "/lightning/lightning.out.js" /> < div id = "LightningComponentid" /> < script > $Lightning.use("c:LightVFExampleApp", function() { $Lightning.createComponent("c:LightVFExample", { }, "LightningComponentid", function(cmp) { console.log('Display Lightning component in visualforce page'); }); }); </ script > </ apex:page > |
Use Lightning Components in Visualforce Pages output
This is lightning component with in visualforce page
In the above Visualforce page, apex:includeLightning tag imports necessary dependencies and scripts to enable Visualforce to act as Lightning component container.
We can use $Lightning.use() method in JavaScript to refer to Lightning Application which extends ltng:outApp.
We can use $Lightning.createComponent create Lightning Component dynamically.
We can call $Lightning.use() multiple times on a page, but all calls must reference the same Lightning dependency app.
We can find more detail over salesforce officail document
No comments:
Post a Comment