๐ก AURA Coexistence
โ @api: LWC ๊ตฌ์ฑ ์์์ ๊ณต์ฉ ์์ฑ ๋๋ ๋ฉ์๋๋ฅผ ๋
ธ์ถํ๋ ๋ฐ ์ฌ์ฉ.
โ @wire: LWC ๊ตฌ์ฑ ์์์ ์์ฑ ๋๋ ๋ฉ์๋๋ฅผ ๋ฐ์ดํฐ ์์ค์ ์ฐ๊ฒฐํ๋ ๋ฐ ์ฌ์ฉ.
โ @track: LWC ๊ตฌ์ฑ ์์์ ์์ฑ์ ๋ํ ๋ณ๊ฒฝ ์ฌํญ์ ์ถ์ ํ๋ ๋ฐ ์ฌ์ฉ.
๐ Decoration ์ฐธ๊ณ
๐งถ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.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");
}
}
1. Event() ์์ฑ์
2. CustomEvent() ์์ฑ์
๐const customEvent = new CustomEvent(type, options);
type : ์ด๋ฒคํธ์ ์ด๋ฆ
options : ํ๋กํผํฐ๋ฅผ ํฌํจํ๋ ๊ฐ์ฒด, ์๋ต ๊ฐ๋ฅ
โ detail : ์ธ๋ถ์ ๋ณด๋ฅผ ๋ํ๋ด๋ ๊ฐ, ๊ธฐ๋ณธ๊ฐ์ null
โ bubbles : ์ด๋ฒคํธ๊ฐ ์์์์๋ก ์ ๋ฌ๋์ด์ผ ํ๋์ง์ ๋ํ ์ฌ๋ถ ๊ฒฐ์ ๊ฐ๋ฅ.
โ cancelable : ์ด๋ฒคํธ๋ฅผ ์ทจ์ํ ์ ์๋์ง์ ๋ํ ์ฌ๋ถ ์ค์
โ composed : Shadow DOM ์์ ์ค์ DOM ์ผ๋ก ์ ํ๋์ด์ผ ํ๋์ง์ ๋ํ ์ฌ๋ถ ๊ฐ๋ฅ.
๐(ํ์ ์ธ๊ฐ์ ๊ฐ์ ๋ถ๋ฆฌ์ธ ๊ฐ์ผ๋ก ์ค์ ๊ฐ๋ฅ, ๊ธฐ๋ณธ๊ฐ์ false)
๐ CustomEvent() ์ฐธ๊ณ
๐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.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.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'));
}
})