Skip to content

Instantly share code, notes, and snippets.

@arun12209
Last active January 29, 2023 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/d523a273a5f1cd7254b472f6ad3c0adc to your computer and use it in GitHub Desktop.
Save arun12209/d523a273a5f1cd7254b472f6ad3c0adc to your computer and use it in GitHub Desktop.
import { LightningElement } from 'lwc';
export default class Weather extends LightningElement {
city = '';
temperature = '';
humidity = '';
description = '';
handleCityChange(event) {
this.city = event.target.value;
}
async getWeather() {
const apiKey = 'your-api-key';
const url = `https://api.openweathermap.org/data/2.5/weather?q=${this.city}&appid=${apiKey}`;
const response = await fetch(url);
const data = await response.json();
this.temperature = data.main.temp;
this.humidity = data.main.humidity;
this.description = data.weather[0].description;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment