Salesforce

Salesforce LWC notification(alert,confirm,prompt)

박성하하 2023. 12. 4. 14:51
728x90
반응형

1.

lwc html

import { LightningElement } from 'lwc';
import LightningAlert from "lightning/alert";
import LightningPrompt from "lightning/prompt";
import LightningConfirm from "lightning/confirm";

export default class NotificationLWC extends LightningElement {
    async handleAlert(){
     await LightningAlert.open({
        message : "Sample Alert Message",
        theme : "error",
        label: "Alert Header"
     }) .then(()=>{
        console.log('###Alert Closed');
     })
    }

    async handleConfirm(){
        const result = await LightningConfirm.open({
           message : "Sample Confirm Message",
           theme : "Success",
           label: "Confirm Header"
        })
           console.log('###Result : ' +  result);
       }

       async handlePrompt(){
        await LightningPrompt.open({
           message : "Sample Prompt Message",
           theme : "error",
           label: "Prompt Header",
           defaultValue:'Test'
        }) .then((result)=>{
           console.log('###Result : ' + result);
        })
       }
}

결과화면

- notification(alert,confirm,prompt)는 import해야한다.
-   async로 function 관리하며, await ~~.open으로 message,theme,label,defaultValue등 관리한다.

 

 

 

 

728x90
반응형