Update Weather.vue

This commit is contained in:
hwxlikemi 2025-01-26 20:50:24 +08:00 committed by GitHub
parent 172fb4230d
commit 9593cbb24f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,5 +1,6 @@
<template> <template>
<div class="weather" v-if="weatherData.adCode.city && weatherData.weather.weather" <div class="weather" v-if="weatherData.adCode.city && weatherData.weather.weather">
<span>{{ weatherData.adCode.city }}&nbsp;</span>
<span>{{ weatherData.weather.weather }}&nbsp;</span> <span>{{ weatherData.weather.weather }}&nbsp;</span>
<span>{{ weatherData.weather.temperature }}</span> <span>{{ weatherData.weather.temperature }}</span>
<span class="sm-hidden"> <span class="sm-hidden">
@ -19,10 +20,8 @@
<script setup> <script setup>
import { getAdcode, getWeather, getOtherWeather } from "@/api"; import { getAdcode, getWeather, getOtherWeather } from "@/api";
import { Error } from "@icon-park/vue-next"; import { Error } from "@icon-park/vue-next";
// Key // Key
const mainKey = import.meta.env.VITE_WEATHER_KEY; const mainKey = import.meta.env.VITE_WEATHER_KEY;
// //
const weatherData = reactive({ const weatherData = reactive({
adCode: { adCode: {
@ -36,7 +35,6 @@ const weatherData = reactive({
windpower: null, // windpower: null, //
}, },
}); });
// //
const getTemperature = (min, max) => { const getTemperature = (min, max) => {
try { try {
@ -48,7 +46,6 @@ const getTemperature = (min, max) => {
return "NaN"; return "NaN";
} }
}; };
// //
const getWeatherData = async () => { const getWeatherData = async () => {
try { try {
@ -93,7 +90,6 @@ const getWeatherData = async () => {
onError("天气信息获取失败"); onError("天气信息获取失败");
} }
}; };
// //
const onError = (message) => { const onError = (message) => {
ElMessage({ ElMessage({
@ -105,7 +101,6 @@ const onError = (message) => {
}); });
console.error(message); console.error(message);
}; };
onMounted(() => { onMounted(() => {
// //
getWeatherData(); getWeatherData();