mirror of
https://github.com/imsyy/home.git
synced 2025-05-19 12:40:13 +09:00
Update Weather.vue
This commit is contained in:
parent
172fb4230d
commit
9593cbb24f
@ -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 }} </span>
|
||||||
<span>{{ weatherData.weather.weather }} </span>
|
<span>{{ weatherData.weather.weather }} </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();
|
||||||
|
Loading…
Reference in New Issue
Block a user