In order to bring/refer custom labels inside LWC component, You need to import it through ‘@salesforce/label’ scoped module.
Sytax: import lableName from ‘@salesforce/label/NameSpace.labelNameThatWasCreatedInSFDC’;
Note: Here the NameSpace will be ‘c’ for the Labels that were created without a namespace in SFDC. If the label was created with in a package, Then we have to given the package name space.
If it all, We can import multiple Labels into LWC, and we can assign all of the labels to a variable of object. See the example below
Example : For suppose, If we have imported two labels like below:
import {LightningElement} from 'lwc';
import lableName1 from '@salesforce/label/c.CustomLabel1';
import lableName2 from '@salesforce/label/c.CustomLabel2';
export default class ClassName extends LightningElement{
LABELS = {
labelValue1: lableName1,
lableValue2: lableName12
}
}
You can refer the data in html using, LABELS.propertName notation.