Skip to content

Instantly share code, notes, and snippets.

@mfissehaye
Last active February 10, 2022 13:02
Show Gist options
  • Save mfissehaye/69e9ebc761716865f0b4c6dd0193cb6b to your computer and use it in GitHub Desktop.
Save mfissehaye/69e9ebc761716865f0b4c6dd0193cb6b to your computer and use it in GitHub Desktop.
Weather reporter
<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