点击天气网地址,选择城市
有关于城市的代码,就是下面请求的weaid
天气前端html代码
<div>
<img src="../../assets/images/weather_icon.png" id="icon" class="icon"/>
<span id="weather"></span>
</div>
请求方法
引入
import axios from 'axios'
mounted
mounted(){
this.getWeather()
}
methods
getWeather() {
axios
.get(
'http://api.k780.com:88/?app=weather.today&weaid=101190201&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json'
)
.then(res => {
const data = res.data.result
const temperature = data.temperature_curr
const that = this
var iconimg = data.weather_icon
if (temperature || iconimg) {
const icon = document.getElementById('icon')
icon.src = iconimg
const tem = document.getElementById('weather')
tem.innerHTML = temperature
}
})
}