在上面的JS代码中,Chrome控制台不断告诉我未定义第一个“ $”。 我的html文件中有一个名为“ bVid”的类,它附加在按钮上。 我的css文件中也有它,该文件也附加到标题中的html文件中。 谁能帮我? ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我不知道我的代码哪里出错了。 挑战是在页面的 h1 中显示我所在位置的当前温度,但我的控制台告诉我 axios 未定义。 我不确定是不是因为我使用的是代码和框,还是我的代码中遗漏了错误。 谢谢
JS
function showTemperature(response) {
console.log();
let temperature = Math.round(response.data.main.temp);
let heading = document.querySelector("h1");
heading.innerHTML = `The outside temperature is ${temperature}℃`;
}
function retrievePosition(position) {
let latitude = position.coords.latitude;
let longitude = position.coords.longitude;
let units = "metric";
let apiKey = "cb64da9857db4762d73f7ab9b0ccec88";
let apiEndpoint = "http://api.openweathermap.org/data/2.5/weather";
let apiUrl = `${apiEndpoint}?lat=${latitude}&lon=${longitude}&appid=${apiKey}&units=${units}`;
console.log(apiUrl);
axios.get(apiUrl).then(showTemperature);
}
navigator.geolocation.getCurrentPosition(retrievePosition);
HTML
<!DOCTYPE html>
<html>
<head>
<title>She Codes Plus</title>
<meta charset="UTF-8" />
<link href="src/styles.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<img src="images/logo.png" alt="She Codes Plus Logo" class="logo" />
<h1>JavaScript Geolocation API</h1>
<h3>JS Challenge 1</h3>
<p>Log your current latitude and longitude using the Geolocation API</p>
<h3>JS Challenge 2</h3>
<p>Log the current temperature where you are.</p>
<h3>JS Challenge 3</h3>
<p>
Change the h1 of this page by the current temperature
</p>
<script src="src/index.js"></script>
</body>
</html>
你安装了axios吗? 我认为您没有将 Axios 导入到您的文件中。
npm install axios
import axios from 'axios';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.