代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>天气预报</title>
</head>
<body>
<div id="app">
<div>
<input type="text" name="" id="" placeholder="请输入查询的城市" @keyup.enter="searchWeather" v-model="city">
<button>搜索</button>
</div>
<div>
<a href="#" @click="changeCity('北京')">北京</a>
<a href="#" @click="changeCity('上海')">上海</a>
<a href="#" @click="changeCity('广州')">广州</a>
<a href="#" @click="changeCity('深圳')">深圳</a>
</div>
<div>
<ul>
<li v-for="item in weatherlist">
<span>{{item.day}}</span>
<span>{{item.week}}</span>
<span>{{item.air_tips}}</span>
<span>平均气温:{{item.tem}}</span>
</li>
</ul>
</div>
</div>
<!-- vue -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- axios -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
/*
天气预报
请求地址:http://hn216.api.yesapi.cn//?s=App.Common_Weather.WeekWeather&app_key=55167A5D035A144F159E1AB60CD873C6
请求参数:city城市
*/
var app = new Vue({
el: "#app",
data: {
city: "",
weatherlist: []
},
methods: {
searchWeather: function () {
axios.get("http://hn216.api.yesapi.cn//?s=App.Common_Weather.WeekWeather&app_key=55167A5D035A144F159E1AB60CD873C6&city=" + this.city)
.then(
(res) => {
this.weatherlist = res.data.data.weather;
}
)
},
changeCity: function (city) {
this.city = city;
this.searchWeather();
}
}
})
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。