1) wireWithProperty
<template>
<P>
<b>Account Name : {name} </b>
</P>
</template>
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name';
export default class WireWithProperty extends LightningElement {
@api recordId; // ํ์ฌ ๋ณด๊ณ ์๋ ๋ ์ฝ๋ ํ์ด์ง์ ๋ ์ฝ๋ ID๋ฅผ ๊ฐ์ ธ์ฌ ๋ ์ฌ์ฉ(Parent-Child ๊ด๊ณ์์ api๋ Child์์ ์ฌ์ฉ ํด์ผํจ)
@wire(getRecord, {recordId : '$recordId', fields : [ACCOUNT_NAME_FIELD]})
record;
get name() {
return getFieldValue(this.record.data, ACCOUNT_NAME_FIELD);
}
}
2) wireWithFunciton : function์ ์ฌ์ฉํด์ ์๋ฌ์ ๋ํ ์ ์ด ๋ฐ ๋ฐ์ดํฐ๋ฅผ ๊ฐ๊ณ ์จ ํ ์ํํ ๋ก์ง์ ์ถ๊ฐํ ์ ์์
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
export default class WireWithFunction extends LightningElement {
@api recordId;
accounts; // @wire๋ก ๊ฐ์ ธ์จ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
error; // error ์ ์ฅ
@wire(getRecord, { recordId : '$recordId', fields : ['Account.Name']})
wireAccount({ error, data }) {
if(data) {
console.log('### Getting data from wire with function');
this.accounts = data;
} else if(error) {
this.error = error;
console.log('### error : ' + error.body.message);
}
}
}