Javascript 如何在api中将英制单位转换为公制单位?
如何将此API结果从英制单位转换为公制单位。下面是FetchAPI的代码Javascript 如何在api中将英制单位转换为公制单位?,javascript,openweathermap,Javascript,Openweathermap,如何将此API结果从英制单位转换为公制单位。下面是FetchAPI的代码 button.addEventListener('click', function() { fetch('http://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&APPID=501cd47da792c61ec790cdbc6913fced') .then(Response => Response.json(
button.addEventListener('click', function() {
fetch('http://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&APPID=501cd47da792c61ec790cdbc6913fced')
.then(Response => Response.json())
.then(data => console.log(data))
})
正如@Orkhan Alikhanov在评论中所说的,您可以在这个API的url上向metric添加unit参数。像这样:
button.addEventListener('click', function() {
fetch('http://api.openweathermap.org/data/2.5/weather?q=' + inputValue.value + '&units=metric&APPID=501cd47da792c61ec790cdbc6913fced')
.then(Response => Response.json())
.then(data => console.log(data))
})
追加
&单位=公制