Getter in LWC

|
| By Webner

LWC component does not allow us to perform expressions in an HTML file so if we want to achieve any expressions in an HTML file in this case we can complete the expression in our getter in a .js file and then we can use that getter in our HTML file.

  1. Getter executes after our constructor and ConectedCallback.
  2. We need to use the “get” keyword before the function to make a getter function.
  3. If the value which we have used in the getter is changed the getter always re-evaluates the value and shows the result accordingly.

Example:-

getter
getter1
getter2

Output:-

getter3

Leave a Reply

Your email address will not be published. Required fields are marked *