aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/services/OpenWeather.vue19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue
index 8029716..0fc1fe5 100644
--- a/src/components/services/OpenWeather.vue
+++ b/src/components/services/OpenWeather.vue
@@ -19,7 +19,7 @@
19 </figure> 19 </figure>
20 </div> 20 </div>
21 <div class="media-content"> 21 <div class="media-content">
22 <p class="title is-4">{{ item.location }}</p> 22 <p class="title is-4">{{ locationName }}</p>
23 <p class="subtitle is-6"> 23 <p class="subtitle is-6">
24 <template v-if="item.subtitle"> 24 <template v-if="item.subtitle">
25 {{ item.subtitle }} 25 {{ item.subtitle }}
@@ -78,6 +78,12 @@ export default {
78 } 78 }
79 return ""; 79 return "";
80 }, 80 },
81 locationName: function () {
82 if (this.api) {
83 return this.api.name;
84 }
85 return "";
86 },
81 temp: function () { 87 temp: function () {
82 if (this.api && this.api.main.temp !== "") { 88 if (this.api && this.api.main.temp !== "") {
83 return parseInt(this.api.main.temp).toFixed(1); 89 return parseInt(this.api.main.temp).toFixed(1);
@@ -102,7 +108,16 @@ export default {
102 }, 108 },
103 methods: { 109 methods: {
104 fetchStatus: async function () { 110 fetchStatus: async function () {
105 const url = `https://api.openweathermap.org/data/2.5/weather?q=${this.item.location}&appid=${this.item.apiKey}&units=${this.item.units}`; 111 let locationQuery;
112
113 // If a specific location ID was specified, use it. Otherwise retrieve value from location (name).
114 if (this.item.locationId) {
115 locationQuery = `id=${this.item.locationId}`;
116 } else {
117 locationQuery = `q=${this.item.location}`;
118 }
119
120 const url = `https://api.openweathermap.org/data/2.5/weather?${locationQuery}&appid=${this.item.apiKey}&units=${this.item.units}`;
106 this.api = await fetch(url) 121 this.api = await fetch(url)
107 .then((response) => response.json()) 122 .then((response) => response.json())
108 .catch((e) => { 123 .catch((e) => {