-
-
Save arun12209/d523a273a5f1cd7254b472f6ad3c0adc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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