Notes
In this example, a user enters their first and last name. A JavaScript getter computes a new value, uppercasedFullName, and the template renders it.
The fullName
property in the template is bound to the get fullName() getter in the JavaScript class.
fullName.html
<template>
<lightning-input name='firstName' label="First Name" onchange={firstNameHandler}></lightning-input>
<lightning-input name='lastName' label="Last Name" onchange={lastNameHandler}></lightning-input>
<p>Full Name: {fullName}</p>
</template>
fullName.js
import { LightningElement } from 'lwc';
export default class FullName extends LightningElement {
firstName = '';
lastName = '';
firstNameHandler(event){
this.firstName=event.target.value;
}
lastNameHandler(event){
this.lastName=event.target.value;
}
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
}