๐Ÿ“™์ผ์ง€_230722(EP.5)

__Dev_1ยท2023๋…„ 7์›” 26์ผ
0

Salesforce

๋ชฉ๋ก ๋ณด๊ธฐ
4/15
post-thumbnail

LWC and AURA Coexistence

๐Ÿ’ก AURA Coexistence

๐Ÿธ Decoration

โ— @api: LWC ๊ตฌ์„ฑ ์š”์†Œ์˜ ๊ณต์šฉ ์†์„ฑ ๋˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ๋…ธ์ถœํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ.
โ— @wire: LWC ๊ตฌ์„ฑ ์š”์†Œ์˜ ์†์„ฑ ๋˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ๋ฐ์ดํ„ฐ ์†Œ์Šค์— ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ.
โ— @track: LWC ๊ตฌ์„ฑ ์š”์†Œ์˜ ์†์„ฑ์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ถ”์ ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ.
   

๐ŸŽƒ Decoration ์ฐธ๊ณ 


myAuraComponent

๐ŸงถmyAuraComponent.html
<<aura:component implements="flexipage:availableForAllPageTypes">
    <lightning:card title="Aura Hello World" iconName="custom:custom14"></lightning:card>
    <c:lwcHelloWorld aura:id="childLwc" name="Kapil"/>
    <lightning:button label="Neutral" value="Test Button" onclick="{!c.myAction}"></lightning:button>
</aura:component>
๐ŸงถmyAuraComponentController.js
({
    myAction: function(component, event, helper) {
       component.find("childLwc").callMe();
    }
})

lwcHelloWorld

๐ŸŽกlwcHelloWorld.html
<<template>
    <lightning-card title="LWC Hello World" icon-name="custom:custom4">
        <div class="slds-card_body">
            Hello, {name}
        </div>
    </lightning-card>
</template>
๐ŸŽกlwcHelloWorld.js
import { LightningElement, api } from 'lwc';

export default class LwcHelloWorld extends LightningElement {
  @api name;
  @api 
  callMe(){
    console.log("###Hello World");
  }

}

๐Ÿธ CuntomEvent

1. Event() ์ƒ์„ฑ์ž
2. CustomEvent() ์ƒ์„ฑ์ž
๐ŸŽˆconst customEvent = new CustomEvent(type, options);

type : ์ด๋ฒคํŠธ์˜ ์ด๋ฆ„
options : ํ”„๋กœํผํ‹ฐ๋ฅผ ํฌํ•จํ•˜๋Š” ๊ฐ์ฒด, ์ƒ๋žต ๊ฐ€๋Šฅ

โ— detail : ์„ธ๋ถ€์ •๋ณด๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ’, ๊ธฐ๋ณธ๊ฐ’์€ null
โ— bubbles : ์ด๋ฒคํŠธ๊ฐ€ ์ƒ์œ„์š”์†Œ๋กœ ์ „๋‹ฌ๋˜์–ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€ ๊ฒฐ์ • ๊ฐ€๋Šฅ.
โ— cancelable : ์ด๋ฒคํŠธ๋ฅผ ์ทจ์†Œํ•  ์ˆ˜ ์žˆ๋Š”์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€ ์„ค์ •
โ— composed : Shadow DOM ์—์„œ ์‹ค์ œ DOM ์œผ๋กœ ์ „ํŒŒ๋˜์–ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์—ฌ๋ถ€ ๊ฐ€๋Šฅ.
๐ŸŽ‡(ํ•˜์œ„ ์„ธ๊ฐœ์˜ ๊ฐ’์€ ๋ถˆ๋ฆฌ์–ธ ๊ฐ’์œผ๋กœ ์„ค์ •๊ฐ€๋Šฅ, ๊ธฐ๋ณธ๊ฐ’์€ false)      

๐ŸŽƒ CustomEvent() ์ฐธ๊ณ 



AccountController

๐Ÿ””AccountController
 public with sharing class AccountController {

    @AuraEnabled(cacheable=true)
    public static List<Account> getAccList(){
        List<Account> acc = [select Id , Name from Account];
        return acc;
    }
}

myAuraComponent

๐Ÿ””myAuraComponent.html
<<aura:component implements="flexipage:availableForAllPageTypes">
   <lightning:card title="Aura Hello World" iconName="custom:custom14"></lightning:card>
   <c:lwcHelloWorld aura:id="childLwc" name="Kapil"/>
   <lightning:button label="Neutral" value="Test Button" onclick="{!c.myAction}"></lightning:button>
</aura:component>
๐Ÿ””myAuraComponent.js
({
   handleAccountSelect : function(component, event, helper) {
       console.log('###Id om AURA:' + event.getParam('accountId'));
       console.log('###Name om AURA:' + event.getParam('accountName'));
   }
})

getAccountList

โœจgetAccountList.html
    <template>
    <!-- <lightning-card title="Wire with for each" icon-name="utility:user">
        <div class="slds-var-m-around_medium">
            <template if:true={accounts.data}>
                <template for:each={accounts.data} for:item="account">
                    <a href="#" key={account.Id} onclick={handleSelect}>
                        <lightning-layout>
                            <lightning-layout-item padding="horizontal-small">
                                <p>{account.Name}</p>
                                <br/>
                            </lightning-layout-item>
                        </lightning-layout>
                    </a>
                </template>
            </template>
        </div>
    </lightning-card> -->
    <br/>

    <lightning-card class="Wire with iterator" title="Wire with iterator" icon-name="utility:user">
        <div class="slds-var-m-around_medium">
            <template if:true={accounts.data}>
                <template iterator:it={accounts.data}>
                    <a href="#" key={it.value.Id} onclick={handleSelect} data-account-id={it.value.Id}
                    data-account-name={it.value.Name}>
                        <lightning-layout>
                            <lightning-layout-item padding="horizontal-small">
                                <div if:true={it.first}>
                                    <div style="border: 5px solid black;"></div>
                                </div>
                                <p>{it.value.Name}</p>
                                <div if:false={it.last}></div>
                                <hr/>
                            </lightning-layout-item>
                        </lightning-layout>
                    </a>
                </template>
            </template>
        </div>
    </lightning-card>
    </template>
โœจgetAccountList.js
({
   handleAccountSelect : function(component, event, helper) {
       console.log('###Id om AURA:' + event.getParam('accountId'));
       console.log('###Name om AURA:' + event.getParam('accountName'));
   }
})
profile
๋ฉ”๋ชจ์žฅ :)

0๊ฐœ์˜ ๋Œ“๊ธ€