我只想编写一个用于学习JS的简单天气应用程序。搜索整个网络后我找不到错误的地方...
我没有从API获得任何信息。我在浏览器控制台中检查了这一点。
我只想显示洛杉矶的当前天气情况。
window.addEventListener("load", () => {
let temperatureDescription = document.querySelector(".temperature-description");
let temperatureDegree = document.querySelector(".temperature-degree");
let locationTimezone = document.querySelector(".location-timezone");
const proxy = "https://cors-anywhere.herokuapp.com/";
const api = '${proxy}https://api.darksky.net/forecast/4d5ddfbfc8eabb0dddcb9e78fb408a99/37.8267,-122.4233';
fetch(api)
.then(response => {
return response.json();
})
.then(data => {
console.log(data);
const {
temperature,
summary
} = data.currently;
temperatureDegree.textContent = temperature;
temperatureDescription.textContent = summary;
locationTimezone.textContent = data.timezone;
});
});
答案 0 :(得分:3)
从快速的概览看,您似乎使用了错误的引号。
尝试将您的API变量放入NETWORK_CONFIGURATION='{"awsvpcConfiguration":{"AssignPublicIp":"ENABLED","SecurityGroups": \["'${AWS_NETWORKCONFIG_SECURITY_GROUP}'"],"Subnets":["'${AWS_NETWORKCONFIG_SUBNET}'"]}}'
而不是aws events put-targets \
--rule events-rule--${TASK_NAME} \
--targets '{"Arn":"arn:aws:ecs:'${AWS_REGION}':'${AWS_ACCOUNT_ID}':cluster/ecs-cluster-1","EcsParameters":{"LaunchType":"FARGATE","NetworkConfiguration":'${NETWORK_CONFIGURATION}',"TaskCount": 1,"TaskDefinitionArn": "arn:aws:ecs:'${AWS_REGION}':'${AWS_ACCOUNT_ID}':task-definition/ecs-task-'${TASK_NAME}'"},"Id": "ecs-targets-'${TASK_NAME}'","RoleArn": "arn:aws:iam::'${AWS_ACCOUNT_ID}':role/ecsEventsRole"}' \
;
。