nuxt-weather-module 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -9,44 +9,16 @@
|
|
|
9
9
|
</template>
|
|
10
10
|
|
|
11
11
|
<script setup>
|
|
12
|
-
import { computed,
|
|
13
|
-
import { useRuntimeConfig
|
|
12
|
+
import { computed, ref, onMounted } from "vue";
|
|
13
|
+
import { useRuntimeConfig } from "#app";
|
|
14
14
|
import { $fetch } from "ofetch";
|
|
15
15
|
import { WEATHER_CODE_MAP } from "../utils/constants";
|
|
16
16
|
const status = defineModel("status", { type: String, ...{
|
|
17
|
-
default: "
|
|
17
|
+
default: "idle"
|
|
18
18
|
} });
|
|
19
|
-
watch(
|
|
20
|
-
status,
|
|
21
|
-
(newStatus) => {
|
|
22
|
-
if (newStatus === void 0) {
|
|
23
|
-
status.value = "pending";
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
{ immediate: true }
|
|
27
|
-
);
|
|
28
19
|
const config = useRuntimeConfig();
|
|
29
20
|
const { latitude, longitude } = config.public.weatherModule;
|
|
30
|
-
const
|
|
31
|
-
status: asyncStatus,
|
|
32
|
-
data,
|
|
33
|
-
error
|
|
34
|
-
} = await useLazyAsyncData(
|
|
35
|
-
"weather-icon",
|
|
36
|
-
() => $fetch(
|
|
37
|
-
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true`
|
|
38
|
-
)
|
|
39
|
-
);
|
|
40
|
-
watch(
|
|
41
|
-
asyncStatus,
|
|
42
|
-
(newStatus) => {
|
|
43
|
-
status.value = newStatus;
|
|
44
|
-
},
|
|
45
|
-
{ immediate: true }
|
|
46
|
-
);
|
|
47
|
-
if (error.value) {
|
|
48
|
-
console.error("Error fetching weather data:", error.value);
|
|
49
|
-
}
|
|
21
|
+
const data = ref(null);
|
|
50
22
|
const setIcon = computed(() => {
|
|
51
23
|
if (!data.value?.current_weather) return "partly-cloudy-day";
|
|
52
24
|
const { weathercode, is_day } = data.value.current_weather;
|
|
@@ -54,6 +26,18 @@ const setIcon = computed(() => {
|
|
|
54
26
|
if (!iconSet) return "partly-cloudy-day";
|
|
55
27
|
return is_day === 1 ? iconSet.day : iconSet.night;
|
|
56
28
|
});
|
|
29
|
+
onMounted(async () => {
|
|
30
|
+
status.value = "pending";
|
|
31
|
+
try {
|
|
32
|
+
data.value = await $fetch(
|
|
33
|
+
`https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t_weather=true`
|
|
34
|
+
);
|
|
35
|
+
status.value = "success";
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error("Error fetching weather data:", error);
|
|
38
|
+
status.value = "error";
|
|
39
|
+
}
|
|
40
|
+
});
|
|
57
41
|
const iconSize = config.public.weatherModule.iconSize;
|
|
58
42
|
</script>
|
|
59
43
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-weather-module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A Nuxt module for displaying dynamic weather icons from Open-Meteo API with configurable coordinates",
|
|
5
5
|
"author": "LobergDesign",
|
|
6
6
|
"homepage": "https://github.com/LobergDesign/weather-module#readme",
|