Last active
February 10, 2022 13:02
-
-
Save mfissehaye/69e9ebc761716865f0b4c6dd0193cb6b to your computer and use it in GitHub Desktop.
Weather reporter
This file contains hidden or 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
<template> | |
<div> | |
<div>{{ WeatherData }}</div> <!-- Show weather data here --> | |
<form action="#" @submit.prevent="getWeatherData"> | |
<input v-model="zipCode" type="text" placeholder="Enter your ZIP code" /> | |
</form> | |
</div> | |
</template> | |
<script> | |
const countryCode = 'US' | |
const apiKey = '' // the openweathermap api key | |
export default { | |
data() { | |
return { | |
zipCode: '', | |
weatherData: null, | |
} | |
}, | |
methods: { | |
async getWeatherData() { | |
this.weatherData = await fetch(`api.openweathermap.org/data/2.5/weather?zip=${this.zipCode},${countryCode}&appid=${apiKey}`).then(res => res.json()) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment