【发布时间】:2022-11-23 03:24:47
【问题描述】:
请尝试在我的 vue js web 应用程序中获取开放天气 api 这是错误,请问我该如何解决这个问题 这是错误: “无效的 API 密钥。请参阅 https://openweathermap.org/faq#error401 了解更多信息。”
这是我的 vue js 代码:
<template></template>
<script>
import { onMounted, ref } from "@vue/runtime-core";
export default {
setup() {
const weatherData = ref([]);
const latitude = ref("");
const longitude = ref("");
onMounted(() => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position) => {
latitude.value = position.coords.latitude;
longitude.value = position.coords.longitude;
});
} else {
alert("Your Browser Doesn't support Geolocation");
console.log("Your Browser do not Support Geolocation");
}
fetch(
`https://api.openweathermap.org/data/2.5/weather?lat={${latitude.value}}&lon={${longitude.value}}&appid={dace6a593d778f8773c2fd033a16a91a}`
)
.then((data) => data.json())
.then((response) => {
weatherData.value = response;
console.log(response);
})
.catch((err) => console.log(err.message));
});
},
};
</script>
<style>
</style>
我期待结果 json格式请帮忙
【问题讨论】:
-
嘿伙计,你的 api 密钥是字符串,所以尝试将它作为一个传递,
appid=dace6a...(没有 {})
标签: vue.js