问题描述
我该如何解决这个异步问题(我认为)。为什么在提取之前不读取输入。
const key=<API-KEY>
const searchInput = document.querySelector(".bottom");
const form = document.querySelector(".search-Box");
let searchValue;
form.addEventListener('input',updateInput);
searchInput.addEventListener('submit',(e) =>{
e.preventDefault();
findcity(searchValue);
})
function updateInput(e){
searchValue=e.target.value;
console.log(e.target.value);
}
async function findcity(query){
const datafetch = await fetch(`http://api.openweathermap.org/data/2.5/weather?q=${query}+&appid=${key}`)
.then(response =>{
let data= response.json()
.then((data) => {
console.log(data);
})
})
}
findcity();
在这里,我更新了输入值,它可以在控制台日志中工作 在我加载他找不到城市的页面时,console.log数据会给我留下深刻的印象
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)